Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Extract a small part of a long sentence using regular expressions

by karlgoethebier (Abbot)
on Dec 02, 2014 at 15:07 UTC ( [id://1108968]=note: print w/replies, xml ) Need Help??


in reply to Extract a small part of a long sentence using regular expressions

Eclectic TIMTOWTDI:

use Data::Dump; use strict; use warnings; my $line = qq([AHB_REPORTER][INFO]: action(62,1,0,0,0,0,5,53,9,0,190)D:/XYZ/reg/T +ests/Mcu/A_test.cCALL: (null)); my $key = q(a); my %hash = map { $key++ => $_ } grep { $_ != 0 } &{ sub { $line =~ /action\(([^)]+)\)/; split /,/, $1; } }; dd \%hash; __END__ { a => 62, b => 1, c => 5, d => 53, e => 9, f => 190 }

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

  • Comment on Re: Extract a small part of a long sentence using regular expressions
  • Download Code

Replies are listed 'Best First'.
Re^2: Extract a small part of a long sentence using regular expressions
by Anonymous Monk on Dec 02, 2014 at 15:53 UTC
    Thanks Karl! Might be a dumb question(with Perl i am always in the figuring out stage!!) but what does  &{ sub { blah } do exactly??
      It's a dereference, I'd rather (if ever) write it as
      my %hash = map { $key++ => $_ } grep { $_ != 0 } sub { $line =~ /action\(([^)]+)\)/; split /,/, $1; }->();
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        "It's a dereference..."

        Thank you for answering this question for me.

        But i'm Karl and you are Choroba, isn't it?

        "...(if ever)..write it"

        May be - if you make so. But there is nothing wrong with the syntax i used to dereference a anonymous sub.

        Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        Got it!! Cheers!
      "Might be a dumb question..."

      Sorry - my fault. I should have mentioned this. Please see perlsub as well as anonymous functions.

      Regards, Karl

      P.S.: There are no dumb questions. Just dumb answers ;-)

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found