Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much


by amoura (Initiate)
on Jul 11, 2002 at 14:28 UTC ( #181028=perlquestion: print w/replies, xml ) Need Help??
amoura has asked for the wisdom of the Perl Monks concerning the following question:

Hello , I have this pice of code where I am trying to grep from a file two things , the first .bld file and one of the directoy which is two level up of that file :
open(OUTNbssbase, "< $tempDir/nbssbaseblds.txt") || die "Could not open file2 : $!\n"; my @hold1; while (<OUTNbssbase>) { push(@hold1, $1) && last if (m/(\w+\.bld)/); } my $hold11 = join(' ', @hold1); close(OUTNbssbase) or die("Can't close file: $!");
my .txt file look like this :
nbssbase/acn/bld/libacnsGH040.bld:acnss.cxx nbssbase/acn/bld/libacnsGH040btsc.bld:acnss.cxx nbssbase/acn/bld/libacnsGH040eel.bld:acnss.cxx
now I am able to capture the first .bld but I need also to capture the "acn" which is two level up ,, I am finding this hard to do when using push and last ,, any ideas or better way .. thanks for help

2002-07-10 Edit by Corion : Fixed closing CODE tags, removed markup from within CODE tags

Replies are listed 'Best First'.
Re: parsing
by helgi (Hermit) on Jul 11, 2002 at 15:13 UTC

    Fellow Perlmonks.

    This person has been asking this question over and over and over again in comp.lang.perl.misc, alt.perl and probably in other places, including here. S/he posts under various names including Sami and Sara. She has received a number of useful answers as well as requests for further info, but never answers them, just keeps posting the same question over and over (and over) again. I suggest you ignore him/her.

    Helgi Briem
      On PerlMonks this person appears as sara, DS, splitOnce, and amoura, and perhaps others. Maybe PerlMonks will soon be earning some credits towards a CS degree.


Re: parsing
by Abigail-II (Bishop) on Jul 11, 2002 at 14:46 UTC
    Why are you doing all the juggling with @hold1 if you are going to bail out after the first hit anyway? Why not something like:
    open my $fh => "$tempDir/nbssbaseblds.txt" or die "Open failed: $! +\n"; while (<$fh>) { my @parts = split m :/: => (split m /:/) [0]; # Split into pat +h names. if ($parts [-1] =~ /^\w+\.bld$/) # Match on file +name. ... whatever ... # $parts [-3] eq + "acn" last; } }


Re: parsing
by bjelli (Pilgrim) on Jul 11, 2002 at 14:45 UTC

    After your loop the last line read is still in $_, so you can use

    @path = split(/\//, $_); $importantdir = $path[-3];

    the negative index in the array counts from the end of the array rather than the beginning.

    Brigitte    'I never met a chocolate I didnt like'    Jellinek
Re: parsing
by bronto (Priest) on Jul 11, 2002 at 16:48 UTC

    You here again? Again with a question with this script?

    Are you trying to learn Perl or are you trying to make us write the code you are supposed to write?

    I never refuse a reply, even on trivial questions, but you seem to lack on education IMHO


    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->made($love) ;

      I am not going to go down to your level , I though this is a place to get help , thats why I come here , if you don't like my question then don't read it . and by the way , I think you are the one who doesn't know what education mean
        In the short time I've been coming to this site for help, I've seen your question posted ....newly least once each day! And each day, I've seen that the VOLUNTEERS of the site have to fix it so it's readable, and I see that the other VOLUNTEERS here have patiently answered your question....many many many times over.

        This is the FIRST Time I've seen you reply to any of their posts, and it's not to say thanks, or to offer some explanation for your odd's to flame them for getting frustrated with you.

        This in itself speaks volumes for your character, who cares about your education level.

        "Great Spirits Often Encounter Violent Opposition From Mediocre Minds" --Albert Einstein

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://181028]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-06-24 11:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.