Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: do $n exist in grep?

by hippo (Chancellor)
on May 12, 2021 at 14:37 UTC ( #11132488=note: print w/replies, xml ) Need Help??


in reply to do $n exist in grep?

Not that I'm aware of. But you can always DIY:

$ perl -E 'grep { /^..(A|B)./ and push @f, $1 } @ARGV; say @f' xxBxx y +yAyy BA $

🦛

Replies are listed 'Best First'.
Re^2: do $n exist in grep?
by LanX (Cardinal) on May 12, 2021 at 16:28 UTC
      or even easier

      DB<34> @a = qw/xxBxx yyAyy zzNzz/ DB<35> @N = map {/^..(A|B)./} @a DB<36> x @N 0 'B' 1 'A' DB<37>

      Hint: m// returns an empty list if there's no match

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

Re^2: do $n exist in grep?
by misterperl (Monk) on May 12, 2021 at 14:47 UTC
    nice , TY u got an UPVOTE!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2021-07-27 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?