Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: perl string extract

by prasadbabu (Prior)
on Oct 04, 2010 at 06:28 UTC ( #863265=note: print w/replies, xml ) Need Help??

in reply to perl string extract

Please ignore this node.

Something like this?

use strict; use warnings; my $line = 'logfile = filename , abcd=eflk , cxd'; my $file; if ($line =~ /logfile\s*\=\s*(.+?)\s*\,?/){ $file=$1; } print "logfile=$file"; output: ======= logfile=filename
Updated: Misunderstood the question. Added '?' after comma to make it optional.

eyepopslikeamosquito++ Thanks.


Replies are listed 'Best First'.
Re^2: perl string extract
by eyepopslikeamosquito (Chancellor) on Oct 04, 2010 at 06:41 UTC

    Your regex:

    if ($line =~ /logfile\s*\=\s*(.+?)\s*\,/){
    unilaterally matches a comma and so does not seem to match the OP's requirement to match with or without a comma.

Re^2: perl string extract
by eyepopslikeamosquito (Chancellor) on Oct 04, 2010 at 07:07 UTC

    Even after your update:

    if ($line =~ /logfile\s*\=\s*(.+?)\s*\,?/){
    it still does not work correctly because the non-greedy (.+?) matches only the f in filename, so that $file has the value f when it should contain filename.
Re^2: perl string extract
by anu_1 (Acolyte) on Oct 04, 2010 at 07:23 UTC
    I tried this solution but didn't work. The output is  logfile=f

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863265]
[LanX]: IMHO 'ju' for 'u' happens in English where they can't pronounce the French u (or German )
[LanX]: and I'm sure I read that *hotel* used to be pronounced 'otel by the English upperclass
[Your Mother]: American English vowels are pretty lazy/mumbly in general.
[LanX]: talking about antisemitism, youtube automatic subtitles is entertaining shocking sometimes ... like when offering "Fruit Jews" as a drink
[Your Mother]: ...Come on you King of the Juice...
[Your Mother]: I actually know his kids.
LanX has to go/
[Your Mother]: King Herod's song (Mike D'Abo performed, I think)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-03-27 17:18 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.