in reply to Confusion with Unzip and GREP

Hi! For the second issue, I created a /tmp/index.txt file and I tried your code
opendir D, "/tmp" or die "could not open dir: $!\n"; my @filename = grep(/index/i, readdir D); print @filename;
Well, I get an "1" . I think it's because "grep" returns an array. Did you tried something like "$filename[0]"? This returns correctly the file name "index.txt". I dunno why yesterday it worked...maybe some editing? Hope you help.

Replies are listed 'Best First'.
Re^2: Confusion with Unzip and GREP
by Anonymous Monk on Dec 11, 2014 at 10:49 UTC

    Poppycock!

    #!perl use strict; use warnings; use 5.010; use Data::Dumper; my @list = qw[ Xindex r-index.txt Index.txt notIdx.txt ]; my @file = grep( /index/i , @list ); say Dumper( \@file ); __END__ $VAR1 = [ 'Xindex', 'QIndex', 'r-index.txt', 'Index.txt' ];

    See Eliy's reply about grep-in-scalar-context.

      Correction: given above @list, output should have been (shortened the list while posting but failed to adjust output along the way) ...

      $VAR1 = [ 'Xindex', 'r-index.txt', 'Index.txt' ];

      Sorry Eily for I had misspelled your (pseudo)name.

        It's alright, I hadn't even noticed :)