in reply to 2048 character limit

Try this untested snippet:

#!/usr/bin/perl -w use strict; my $file = '\/etc\/group'; local*FH; open(FH, $file) || die "Cannot open file: $!"; my @contents = <FH>; close FH; print $_ foreach (@contents);

Replies are listed 'Best First'.
Re: Re: 2048 character limit
by Beatnik (Parson) on Jun 05, 2002 at 22:32 UTC
    You can stick a print; inside a while(<FH>) { } to avoid stuffing the memory with file contents...

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Re: 2048 character limit
by druid (Initiate) on Jun 05, 2002 at 23:02 UTC
    Tried this one .. and i get the first part of the group file that i am matching for if (/steel/) i get steel:!:1: but not the list of users in the group .. basically same problem I personally have because this code is the same as what i wrote
      Ahhhh, so you problem isnt reading the file, but matching strings within the file.

      I reckon if you post your code, someone may come up with a solution.

        no .. it matches.. but i dont get the full line and this is because of the character limit..
Re: Re: 2048 character limit
by druid (Initiate) on Jun 06, 2002 at 08:15 UTC
    #!/usr/bin/perl -w open (FILE,"/home/druid/group"); open (FILE2,">/home/druid/t"); while(<FILE>){ if (/steel/){ print FILE2; } } close FILE; close FILE2;
      Try running this:
        
      #!/usr/bin/perl -w use strict; open my $fh_group, "</etc/group" or die "Cannot open group file"; while (<$fh_group>) { chomp; my ($grp, $pwd, $gid, $users) = split /:/; if ($grp eq $ARGV[0]) { my @users = split /,/, $users; print join $/, @users; } }
      Save it to a file, and run it with a command line argument of the group you'd like to check membership for, for example:
      perl program.pl steel
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print