Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

substr complexities

by drock (Beadle)
on Sep 01, 2004 at 17:31 UTC ( #387613=perlquestion: print w/replies, xml ) Need Help??

drock has asked for the wisdom of the Perl Monks concerning the following question:

All, can anyone provide some help? my current output is E00854), Seq #: 000595 in TLU: st_ and all I want is the E string and cannot get my substr working Here is my code:
foreach (split /\n/, $EDM_nonactive_tapelist ) { if (( /\((E\d+)/ ) && ( !m/\*Orig/ ) && ( m/st +_9840_acs_0/ )) { local $, = "\t"; #print OUT "$1\n" unless substr($_, 0, + 5) eq '*Orig'; #my $fooed = substr($_, 29, 34) ; #print "$fooed \n"; print "$1\n" if substr($_, 29, 34) eq +'E0+'; #print "$_ \n"; exit 0; } }

Replies are listed 'Best First'.
Re: substr complexities
by ikegami (Patriarch) on Sep 01, 2004 at 19:26 UTC

    hum, I don't see how this snippet can possibly print what you say it does, or anything at all, for that matter.

    For starters, E0+ is much shorter than 34 chars long, so the only print that isn't commented won't get executed because the if will fail (unless $_ is 32 chars long and ends with 'E0+').

    And then, there's the issue that you are printing $1, yet the last regexp you execute (m/st_9840_acs_0/) doesn't have any captures.

    btw, I think you're using java-style substring arguments. perl uses substr(string, start, length), not substr(string, start, end)

Re: substr complexities
by ikegami (Patriarch) on Sep 01, 2004 at 17:54 UTC

    hum, I don't see how this snippet can possibly print what you say it does, or anything at all, for that matter.

    For starters, E0+ is much shorter than 34 chars long, so the only print that isn't commented won't get executed because the if will fail (unless $_ is 32 chars long and ends with 'E0+').

    And then, there's the issue that you are printing $1, yet the last regexp you execute (m/st_9840_acs_0/) doesn't have any captures.

    btw, I think you're using java-style substring arguments. perl uses substr(string, start, length), not substr(string, start, end)

    Please submit a snippet of code we can execute and displays the error.

Re: substr complexities
by Limbic~Region (Chancellor) on Sep 01, 2004 at 17:36 UTC
    Anonymous Monk,
    You want the E string from what? What does your input look like and specifically is the output you desire? You did good by showing what you have tried but unfortunately my crystall ball is in the shop for repairs and I can't make the leap to what the data actually looks like.

    Cheers - L~R

Re: substr complexities
by Not_a_Number (Prior) on Sep 01, 2004 at 18:59 UTC

    My crystal ball is playing up as well, but consider this extract from perldoc perlre (my emphasis):

    The numbered variables ($1, $2, $3, etc.) ... are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first.

    So it might be that your $1 is getting clobbered by the success of the following regexes. Try changing the order of your if() to the following (some punctuation removed):

    if ( /t_9840_acs_0/ && ! /\*Orig/ && /\((E\d+)/ ) { print "$1\n"; }

    dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2023-01-31 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?