Bug in heredoc

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Bug in heredoc

Post by PeterH »

All following relates to the new, alternative heredoc syntax <<<#>>>

If a heredoc contains just one line, a newline is prepended. If you add a 2nd line it disappears. I think it never should be there!

And I think the logic at the end is not consistent!

Code: Select all

   $v = <<<#>>>
  line 1
  line 2   #>>>;

   $v = <<<#>>>
  line 1
  line 2   
#>>>;

   $v = <<<#>>>
  line 1
  line 2   
    #>>>;
all lead to the same result. But adding a dot to the last example:

Code: Select all

   $v = <<<#>>>
  line 1
  line 2   
  .  #>>>;
...adds a crlf and the group of blanks with the dot to the result, i.e. the result then has 3 lines. I don't think it makes sense this way!

I think (in the case of the alternative syntax) always everything up to the ending # should be included.

admin
Site Admin
Posts: 67330
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug in heredoc

Post by admin »

Confirmed. Agreed. Fixed. Thanks. :)

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in heredoc

Post by PeterH »

admin wrote:Confirmed. Agreed. Fixed. Thanks. :)
~90% OK :whistle:

I think all is fine now at the end of the heredoc.

But my report started with: If a heredoc contains just one line, a newline is prepended. If you add a 2nd line it disappears. I think it never should be there! This is still as before...
Sample (please don't laugh - idiotic heredoc :biggrin: ):

Code: Select all

   $v = <<<#>>>
  line 1  #>>>;

admin
Site Admin
Posts: 67330
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug in heredoc

Post by admin »

OK, the missing ~10% are coming.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in heredoc

Post by PeterH »

admin wrote:OK, the missing ~10% are coming.
Hey - just made it into 10.90.0400 :appl:

Now, after a lot of testing, I found absolutely nothing more to complain about in heredoc (alternative form) :D

From my point of view heredoc (alternative!) is extremely useful, straight and handy this way

And I must say: it is a command I didn't like in the beginning. But I have learned to appreciate it!
Optimal to build some formatted multi-line output!

So: Many Thanks for all the work!

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Bug in heredoc

Post by highend »

Optimal to build some formatted multi-line output!
Mind to post some small examples?

Still haven't got the time to get used to the heredoc syntax :)

Tia,
Highend
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2734
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Bug in heredoc

Post by Filehero »

highend wrote:Still haven't got the time to get used to the heredoc syntax :)
Me too.


Cheers,
Filehero

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in heredoc

Post by PeterH »

highend wrote:
Optimal to build some formatted multi-line output!
Mind to post some small examples?

Still haven't got the time to get used to the heredoc syntax :)

Tia,
Highend
Just some examples for my use of heredoc.
One is "stolen": the $batch= <<<WIN_CLI
All are excerpts from scripts, and all are unrelated.

Some are rather new, others quite old.
Some with old syntax <<<..., others with new <<<#...

Some should be a bit optimized for use of the current syntax.
(This thread shows: last changes were just made by Don.)

In future I will only use the new syntax <<<#... - it's more flexible, and creates exactly what you specify.
And for the optic I (will) prefer <<<#>>>

Here the samples:

Code: Select all

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
   $isok    = Confirm (<<<#>>>
Verify files to compare:
====--------------------

First      File: $file1
Second File: $file2

Output File: $fileo

'Tab'-character = "$s"
   EQ = "$eq"<tab>add key = "$add"
NEQ = "$neq"<tab>del  key = "$del"

===> Is this OK?
#>>>   ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
  $batch= <<<WIN_CLI
cd /d "%~dp0"
start "" /wait /separate $unzip
REM del "$path\XYplorer.zip"
start "" /separate "$path\XYplorer.exe"
REM del "XYplorer.bat"
WIN_CLI;
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Some logic to change the (default!) layout of the toolbar.
// The $barchg= creates a list to change some strings:
// all (trimmed) strings left of "|" will be replaced by the strings right of "|"

 Global $bar, $barchg; //     curr Toolbar, ListOfChanges
   $bar     = GetKey(  /* get curr Toolbar */                  "Toolbar"                    , $s);
   $barchg  = <<<#>>>
mru  |mru,refresh
del  |del,ctb1
dp12 |dp12,syncscroll
     |-,-,steps
#>>>; // ^^ Chg the (trimmed) left vals to the right vals, the last line appends.
   Sub "_ReplaceInBar"; // (Parms: $bar, $barchg)
   SetKey $bar                                               , "Toolbar"                    , $s;
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
   Text <<<#>>>
$Ptext

Anzahl Files renamed   : $renamed
Anzahl Files skipped   : $skipped
                        ---
Anzahl Files gesehen   : $seen
Anzahl Files ausgewählt: $selanz


List of renamed:
----------------
$fdone


List of skipped:
----------------
$fskip
#>>>   , 860, 600, "'RenameSel GPX' $Pstat";
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
   Text <<<#>>>
Script ended.

$nl<tab>Lines read,
$ns<tab>Sections found,
$nk<tab>Keys found,
$nne1<tab>Quoting differences (leading & trailing '"' native in File)
===============================
$nne2<tab>Real differences found.
===============================
#>>>;
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Bug in heredoc

Post by highend »

Thank you, Peter!
One of my scripts helped you out? Please donate via Paypal

Post Reply