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

Re^2: Extracting selected fields form file record

by LanX (Saint)
on Feb 06, 2022 at 18:31 UTC ( [id://11141173]=note: print w/replies, xml ) Need Help??


in reply to Re: Extracting selected fields form file record
in thread Extracting selected fields form file record

another way is filling in undef for the ignored fields

my ($first,$second,undef,$third,undef,$fourth,undef,$fifth,undef,$sixth) = split / /, $line;

please also note that split operates on regexes, so /\s+/ might be what is really wanted.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Extracting selected fields form file record
by soonix (Canon) on Feb 06, 2022 at 19:53 UTC
    A single space character (' ') is a special case. I admit that it is a bit buried in the split documentation. Of course, only at most OP knows whether leading whitespace should be kept…
      you are right and it will also handle leading whitespace! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found