Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Bugfixing Old Code

by NetWallah (Canon)
on Jul 23, 2021 at 00:50 UTC ( [id://11135328]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Bugfixing Old Code
in thread Bugfixing Old Code

Without knowing what the data looks like, here is my guess at what "should" work:
my @temp_and_starts = $_=~/(\S+)/g; my @last_AT_fracs = scalar(<$in>) =~/(\S+)/g; my @twenty_SFs = (<$in> . <$in> . <$in> . <$in>) =~/(\S+) +/sg;

                "The difficult we do today; the impossible takes a little longer."

Replies are listed 'Best First'.
Re^4: Bugfixing Old Code
by bliako (Monsignor) on Jul 23, 2021 at 09:03 UTC

    I thought that required brackets as in my @temp_and_starts = ($_=~/(\S+)/g); but it does not.

      Also note that $_=~ can be shortened to . Moreover, you don't need a capture if you capture the whole pattern.
      my @temp_and_starts = /\S+/g;
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        You are correct - the capturing parens are not necessary,
        In that case, the originally posted code is correct:
        # Split on multiple spaces using regex captured matches my @temp_and_starts = $_ =~ /[^\s +]+/g; my @last_AT_fracs = <$in> =~ /[^\s +]+/g; my @twenty_SFs = (<$in> . <$in> . <$in> . <$in>) =~ /[^\s +]+/g;
        and my test below shows that it works:
        $ perl -E '$_="This and that and other";@x= $_=~ /[^\s]+/g;; say for +@x' This and that and other

                        "The difficult we do today; the impossible takes a little longer."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-26 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found