Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

All of my terms end up in @foo0

by jerrygarciuh (Curate)
on Feb 08, 2002 at 04:19 UTC ( #144028=perlquestion: print w/replies, xml ) Need Help??

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

This snippet creates my array.
if ( !grep { /$term/ } @file ) { $term="$news_directory$term"; push (@delete_me,$term);

This snippet:
    unlink @delete_me or die "Couldn't unlink @delete_me: $!";
works fine on *nix but on this IIs box I get all my terms in the file not found report. So I tried unlinking just @delete_me[0] and carping with @delete_me[0]'s value and lo and behold all the values came back same as when I was printing @delete_me. So I assume this means they are all in that first element. Can anyone enlighten me as to my error?
If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ

Replies are listed 'Best First'.
Re: All of my terms end up in @foo0
by theguvnor (Chaplain) on Feb 08, 2002 at 04:25 UTC
    If you're looking for the first element of @delete_me, you want $delete_me[0]. Unless you're using Perl 6 already ;^)

    Update Yes, @delete_me[0] is valid syntax but not likely what jerrygarciuh was looking for (correct me if I'm wrong ;^)

      @delete_me[0] is a one element array slice. I'm not debating that it's a good thing to do, but it's valid enough.
Re: All of my terms end up in @foo0
by chipmunk (Parson) on Feb 08, 2002 at 04:31 UTC
    One possibility is that something odd happens when you define @file. Not having seen the code, I'll guess that you have a problem with line endings; you're reading in a file containing file names on separate lines, but the mismatch in line endings means they get read in as a single value.

    If that's not it, seeing more of the code would be very helpful.

      Per request here is the code. The commented out bit is just problem solving to be sure it wasn't the culprit.
      Thx for lookin'!
      sub do_the_clean_up { open (ST,"$search_terms_file") or die "where's the search_terms fi +le? : $!"; flock (ST,LOCK_EX) or die "Couldn't flock search_terms: $!"; my @search_terms = <ST>; flock(ST,LOCK_UN); close ST or die "search_terms won't close : $!"; chomp (@search_terms); open (FTS,"$file_to_search") or die "where's the file_to_search? : + $!"; flock (FTS,LOCK_EX) or die "Couldn't flock file_to_search.: $!"; my @file = <FTS>; flock(FTS,LOCK_UN); close FTS or die "Couldn't close file_to_search. : $!"; foreach $term(@search_terms) { if ( !grep { /$term/ } @file ) { $term="$news_directory$term"; push (@delete_me,$term); } else { push (@keep_me,$term); } } chomp @delete_me; unlink @delete_me[0] or die "Couldn't unlink @delete_me[0]: $!"; # open (NEWST,"+< $search_terms_file") or die "where's the search_t +erms file? : $!"; # flock (NEWST,LOCK_EX) or die "Couldn't flock search_terms: $!"; # seek NEWST, 0, 0; # truncate (NEWST,0) or die "Can't truncate: $!"; # foreach (@keep_me) { # print NEWST "$_\n"; # } # flock(NEWST,LOCK_UN); # close NEWST or die "search_terms won't close : $!"; print "Location: $this_script_url\n\n"; exit; }
      If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ
        Ah, just as I had guessed, @file is being read in from an external file. So, the file probably has the wrong line endings for the system. Either convert the file to have the appropriate line endings, or change your code so that it can deal with any line endings.

        Here's a very simple, but probably not optimal, example of the latter:

        { local $/; my @files = split /\r\n?|\n\r?/, <FTS>; }
Re: All of my terms end up in @foo0
by BeernuT (Pilgrim) on Feb 08, 2002 at 04:37 UTC
    might help a little to be able to see your code instead of snippets.

    also you could probably do $news_directory .= $term;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-12-08 01:17 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (34 votes). Check out past polls.