Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Help in joining these lines

by GrandFather (Sage)
on Sep 16, 2016 at 02:45 UTC ( #1171908=note: print w/replies, xml ) Need Help??


in reply to Re: Help in joining these lines
in thread Help in joining these lines

Instead of going through hoops with do and various variables you could just:

open my $fIn, '<', \<<INSTR; > gi|11SB_CUCMA Train|1 21 ... .......................................... INSTR

which saves a bunch of quoting things and messing around generally.

Premature optimization is the root of all job security

Replies are listed 'Best First'.
Re^3: Help in joining these lines
by BillKSmith (Parson) on Sep 16, 2016 at 18:21 UTC

    You do have a point. Of course it would be even easier to use <DATA>. I felt that the quoting offered three advantages.

    The biggest advantage is that it removes the ambiguity related to white space at the end of each line.

    All the data remains on the screen at once.

    The format of the open statement is exactly the same as for reading a disk file.

    Bill

      No, I think your use of a string is the right thing to do in this example. Having the open near the same as you would use for a file is good, especially to demonstrate the three parameter open. I'd tend to use a normal string rather than a string ref just to make it clear magic is happening though.

      I probably went one step too far putting the HEREDOC in the open though, but I was so chuffed to see it worked like that that I couldn't help it. :-D

      I don't think there was ever an issue of trailing white space in the OP's question and I don't see how the "data remains on the screen" comment applies. However, minor points and nothing to really worry about. More to do with style differences than right or wrong ways to do things. In Perl I almost never use the concatenation operator because Perl offers so many other ways to get the job done that appeal more to my eye, and for multiple line stuff my go to tool is the HEREDOC because in code it most looks as it's going to look as output.

      Premature optimization is the root of all job security

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1171908]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-07-16 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (352 votes). Check out past polls.

    Notices?