[28900] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 144 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 16 14:10:09 2007

Date: Fri, 16 Feb 2007 11:09:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 16 Feb 2007     Volume: 11 Number: 144

Today's topics:
    Re: Automated testing of cgi / perl <vilain@spamcop.net>
    Re: Automated testing of cgi / perl <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: find lines in a file <jesse_hardy@premierinc.com>
    Re: find lines in a file <jgibson@mail.arc.nasa.gov>
    Re: find lines in a file <mritty@gmail.com>
        Find Novell file lock information <mike_solomon@lineone.net>
    Re: Geting Windows NT services and drives. <thepoet_nospam@arcor.de>
        How can I deserialize data with Perl serialized with Ja <MisterPerl@gmail.com>
    Re: How to extract .tar files in different directory? au.danji@gmail.com
    Re: How to extract .tar files in different directory? <greg.ferguson@icrossing.com>
    Re: How to extract .tar files in different directory? <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: pattern serach over many files anno4000@radom.zrz.tu-berlin.de
    Re: pattern serach over many files <tadmc@augustmail.com>
    Re: pattern serach over many files <wahab-mail@gmx.de>
    Re: pattern serach over many files <ced@blv-sam-01.ca.boeing.com>
    Re: Perl takes a lot of memory when you just require a  anno4000@radom.zrz.tu-berlin.de
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 16 Feb 2007 09:47:40 -0800
From: Michael Vilain <vilain@spamcop.net>
Subject: Re: Automated testing of cgi / perl
Message-Id: <vilain-83CA30.09474016022007@comcast.dca.giganews.com>

In article <1171565491.430048.105110@j27g2000cwj.googlegroups.com>,
 spam@comjet.com wrote:

> Hello, I have the following situation:
> 
> - Existing site with about 18,000 cgi pages.
> - Most pages are data driven (fill out form, submit, get results).
> Exact results may change from day to day as data get updated.
> - Some static html mixed in
> - Many pages require authentication. It is a custom in-house
> authentication mechanism, but ultimately it stores a temporary session
> ID in a session cookie.
> 
> I would like to implement automated testing that will:
> 
> - Tell me if anything breaks.
> - Tell me if a new installation of the same overall site is working
> the same as the original (for an upgrade project).
> - Tell me if I break anything during maintenance (regression testing)
> 
> Can anyone give me some pointers on this? Tool? Overall approach?
> Pitfalls? Any clues appreciated.
> 
> Larry

I don't know of any tools that can test in a web application 
environment.  The regression testing tool in Unix is expect which is 
command-line only.

With so many pages, there must be an automated test plan.  Otherwise, 
how did the site get so large without detecting and fixing bugs?  Or was 
that what your customers are for?

You can write perl code that uses HTML CPAN libraries to access pages, 
pretending to be a client.  Said connection can input information into 
fields, even store cookies for session ID between pages.

If you don't already have an automated testing environment for your web 
application, it's rather late to start developing one.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...





------------------------------

Date: Fri, 16 Feb 2007 19:09:36 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Automated testing of cgi / perl
Message-Id: <45d5f360$0$25954$ba4acef3@news.orange.fr>

Michael Vilain wrote:
> In article <1171565491.430048.105110@j27g2000cwj.googlegroups.com>,
>  spam@comjet.com wrote:
> 
>> Hello, I have the following situation:
>>
>> - Existing site with about 18,000 cgi pages.
>> - Most pages are data driven (fill out form, submit, get results).
>> Exact results may change from day to day as data get updated.
>> - Some static html mixed in
>> - Many pages require authentication. It is a custom in-house
>> authentication mechanism, but ultimately it stores a temporary session
>> ID in a session cookie.
>>
>> I would like to implement automated testing that will:
>>
>> - Tell me if anything breaks.
>> - Tell me if a new installation of the same overall site is working
>> the same as the original (for an upgrade project).
>> - Tell me if I break anything during maintenance (regression testing)
>>
>> Can anyone give me some pointers on this? Tool? Overall approach?
>> Pitfalls? Any clues appreciated.
>>
>> Larry
> 
> I don't know of any tools that can test in a web application 
> environment.  The regression testing tool in Unix is expect which is 
> command-line only.
I came across Selenium today, which looks rather useful, and has the 
advantage of being able to run tests under various browsers. Also worthy 
of note is jsunit.

> 
> With so many pages, there must be an automated test plan.  Otherwise, 
> how did the site get so large without detecting and fixing bugs?  Or was 
> that what your customers are for?
> 
> You can write perl code that uses HTML CPAN libraries to access pages, 
> pretending to be a client.  Said connection can input information into 
> fields, even store cookies for session ID between pages.
As an addendum to this:

Test::WWW::Mechanize

would be my first port of call.

> 
> If you don't already have an automated testing environment for your web 
> application, it's rather late to start developing one.
He's probably inherited a large and rather crufty application and wants 
to make sure nothing breaks as he tries to knock it into shape. Best of 
luck :)

Mark


------------------------------

Date: 16 Feb 2007 08:40:48 -0800
From: "jesse" <jesse_hardy@premierinc.com>
Subject: Re: find lines in a file
Message-Id: <1171644048.760556.152410@j27g2000cwj.googlegroups.com>

On Feb 14, 11:17 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> On Feb 14, 10:37 am, "Paul Lalli" <mri...@gmail.com> wrote:
>
>
>
>
>
> > On Feb 14, 10:20 am, "jesse" <jesse_ha...@premierinc.com> wrote:
>
> > > On Feb 6, 3:22 pm, "Paul Lalli" <mri...@gmail.com> wrote:
> > > > while (<DATA>) {
> > > >    if (/Error: (.*)/) {
> > > >        $count_of{$1}++;
> > > >    }}
> > > Paul, I have a question. The (.*) is supposed to capture everything
> > > after thematchright?  So if I didn't want to capture everything
> > > after thematchcould this be changed some how to just grab the next
> > > 35charactersafter thematchorbeforethematch?
>
> > Sure it could.
>
> > if (/Error: (.{35})/) {
>
> > or
>
> > if (/(.{35}) Error:/) {
>
> > Please read up on regular expressions:
> > perldoc perlre
> > perldoc perlretut
> > perldoc perlreref
>
> > Paul Lalli
>
> Perfect Paul! Thanks for your help, and I will read those perldocs.- Hide quoted text -
>
> - Show quoted text -

I have found that what you have given still isn't quite what I need.
I have read most of the perldoc on regular expressions but I'm still
not sure how to fix it.  The log files needless to say are not a fix
length or width.  Here is a couple of line from one of the log files.

00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
(5), premature end of file encountered
00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
= socket read failed (23)
00:04:21.876 [775] <2> listen_loop: select() interrupted

What I would like for the script to do is ignore everything up to the
<2> and just process the line after that.  I thought maybe I could do
it with a substr but it doesn't really look like it would work from
what I've read.  Here is the script.

#!/usr/bin/perl -w
#
#This script will check the Netbackup log files on the Master and
Media servers.  It email failures and errors that it finds
 .#
#This script will use functions to check each of the Netbackup log on
the server.
#
use strict;
#use Date::Format;
#
#Function to check the bpsched log
sub bpsched_f {
use Date::Format;
        my $DATE = time2str("%m%d%y", time);
        open (BPSCHED,"</usr/openv/netbackup/logs/bpsched/log.$DATE")
|| die "can't open for reading $!";
        my %count_of;
        open (OUTPUT, ">>/export/home/jhardy/errors/log.$DATE") || die
"can't open log for writing $!";
        while (<BPSCHED>) {
                if (/(.{45})failure(.*)/sm){
                chomp;
                $count_of{$1}++;
}
                elsif (/(.{45})error(.*)/sm) {
                $count_of{$1}++;
}
}
                        for my $failure (keys %count_of) {
                        print OUTPUT "These errors are from the
bpsched log\n";
                        print OUTPUT
"#############################################################################
\n";
                        print OUTPUT "There were $count_of{$failure}
instances of $failure error\n";
                        print OUTPUT "\n";
                        print OUTPUT "\n";

}
}

Everything that I want to ignore on the start of each line is a number
or a space so could I do something like

if ($line =~ (/[^\d\s(.{25})/)
then delete it from the variable, am I anywhere close to being right.







------------------------------

Date: Fri, 16 Feb 2007 09:41:30 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: find lines in a file
Message-Id: <160220070941302968%jgibson@mail.arc.nasa.gov>

In article <1171644048.760556.152410@j27g2000cwj.googlegroups.com>,
jesse <jesse_hardy@premierinc.com> wrote:


> > Perfect Paul! Thanks for your help, and I will read those perldocs.- Hide
> > quoted text -
> >
> > - Show quoted text -
> 
> I have found that what you have given still isn't quite what I need.
> I have read most of the perldoc on regular expressions but I'm still
> not sure how to fix it.  The log files needless to say are not a fix
> length or width.  Here is a couple of line from one of the log files.
> 
> 00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
> (5), premature end of file encountered
> 00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
> = socket read failed (23)
> 00:04:21.876 [775] <2> listen_loop: select() interrupted

if( $line =~ /<2>/ ) {
  my $rest_of_line = $';
  # process rest of line
}

Using $' will slow your program down, although the effect is likely to
be insignificant. If this matters to you, see 'perldoc perlre' and
search for "WARNING" to see why and either use a regular capture
(/<2>(.*)$/) or the @+ array for more efficiency.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: 16 Feb 2007 10:08:07 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: find lines in a file
Message-Id: <1171649287.176156.14170@s48g2000cws.googlegroups.com>

On Feb 16, 11:40 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> On Feb 14, 11:17 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> > On Feb 14, 10:37 am, "Paul Lalli" <mri...@gmail.com> wrote:
> > > On Feb 14, 10:20 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> > > > On Feb 6, 3:22 pm, "Paul Lalli" <mri...@gmail.com> wrote:
> > > > > while (<DATA>) {
> > > > >    if (/Error: (.*)/) {
> > > > >        $count_of{$1}++;
> > > > >    }}
> > > > Paul, I have a question. The (.*) is supposed to capture everything
> > > > after thematchright?  So if I didn't want to capture everything
> > > > after thematchcould this be changed some how to just grab the next
> > > > 35charactersafter thematchorbeforethematch?

> > > if (/Error: (.{35})/) {

> I have found that what you have given still isn't quite what I need.

I gave you exactly what you *asked for*.  I am not a mind reader.  If
you don't need what you ask for, or if you don't ask for what you
need, there's really very little I can do about it.

> I have read most of the perldoc on regular expressions but I'm still
> not sure how to fix it.  The log files needless to say are not a fix
> length or width.  

Then why did you ask very specifically for 35 characters after a given
match?

> Here is a couple of line from one of the log files.
>
> 00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
> (5), premature end of file encountered
> 00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
> = socket read failed (23)
> 00:04:21.876 [775] <2> listen_loop: select() interrupted
>
> What I would like for the script to do is ignore everything up to the
> <2> and just process the line after that.  

I have no idea what you mean by "process the line after that." If you
want the text that comes after the "<2>", then just get it:

if ($line =~ /<2>\s*(.*)/) {
  my $error = $1;
  #do whatever you want with $error;
}


[snip long complicated code snippet]

You need to work on posting short-but-complete scripts that
demonstrate *just* the problem at hand, and remove all the other
cruft.  For example:

#!/usr/bin/perl
use strict;
use warnings;

while (my $line = <DATA>) {
  if ($line =~ /<2>\s*(.*)/) {
    my $error = $1;
    print "The error is: '$error'\n";
  }
}
__DATA__
00:04:21.867 [12870] <2> get_bprdresp: get_string() failed, I/O error
(5), premature end of file encountered
00:04:21.868 [12870] <2> process_request: get_hostinfo failed - status
= socket read failed (23)
00:04:21.876 [775] <2> listen_loop: select() interrupted


Output:
The error is: 'get_bprdresp: get_string() failed, I/O error (5),
premature end of file encountered'
The error is: 'process_request: get_hostinfo failed - status = socket
read failed (23)'
The error is: 'listen_loop: select() interrupted'


Modifying the above for your own needs is left as an excercise for
you.

Paul Lalli



------------------------------

Date: 16 Feb 2007 09:38:12 -0800
From: "mike_solomon@lineone.net" <mike_solomon@lineone.net>
Subject: Find Novell file lock information
Message-Id: <1171647492.162215.48550@q2g2000cwa.googlegroups.com>

At the moment before I run a Perl script I have to use rconsole to
check if any off the files I need to access are in use

Is there anyway using Perl I can check if the file are being used?

I am running on windows with a connection to a Novell server

Thanks



------------------------------

Date: Fri, 16 Feb 2007 16:51:34 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Geting Windows NT services and drives.
Message-Id: <45d5d306$0$23136$9b4e6d93@newsspool1.arcor-online.net>

490 wrote:
> On Feb 15, 8:32 pm, Christian Winter <thepoet_nos...@arcor.de> wrote:
[wmi-example snipped]
> 
> I thought about that but it steel uses lots of CPU.
> Isn't there a perl module way?

Not really. You can either use OLE/WMI, parse the registry manually,
or parse the output of a tool that does either of those. But if the
wmi approach takes too much cpu power, then the system it's running on
is either seriously misconfigured or deadly out-aged. Sorry to say
that.

-Chris


------------------------------

Date: 16 Feb 2007 06:20:17 -0800
From: "Mr P" <MisterPerl@gmail.com>
Subject: How can I deserialize data with Perl serialized with Java?
Message-Id: <1171635617.693462.108450@h3g2000cwc.googlegroups.com>

Our Java team (you know the language- the one that needs 3000 lines
and 25 classes to say HELLO WORLD), using tomcat, has stored some page
results into a MYSQL LARGE BLOB, serialized.  I can fetch the blob
into a Perl scalar. But attempts to deserialize it have been
unsucessful.

After researching Perl Data::Serializer , I sent the JAVA the 8 types
of supported serialized data. The Java guy said he had no idea which
would apply. I've been trying all of them with either errors, or no
data returned.  I also tried deserialize_raw() which results in:

Use of inherited AUTOLOAD for non-method
Data::Serializer::Data::Dumper::SCALAR() is deprecated at (eval 8)
[blib/lib/Data/Serializer/Data/Dumper.pm (autosplit into blib/lib/auto/
Data/Serializer/Data/Dumper/deserialize.al):98] line 1.
Data::Serializer error: Can't locate auto/Data/Serializer/Data/Dumper/
SCALAR.al in @INC

Googling  for SCALAR.al produces nada. (What *is* a .al file anyhow?)

Anyhow, what looked simple has basically turned into a PITA. Advice is
appreciated and most certain NOT deprecated !

Gracias and Happy Friday,
MP



------------------------------

Date: 16 Feb 2007 06:42:02 -0800
From: au.danji@gmail.com
Subject: Re: How to extract .tar files in different directory?
Message-Id: <1171636922.873085.180890@v33g2000cwv.googlegroups.com>

On Feb 15, 4:29 pm, "mar...@gmail.com" <mar...@gmail.com> wrote:
> On Feb 15, 4:16 pm, "Dan" <whd...@gmail.com> wrote:
>
>
>
> > Hi, could anyone tell me how to do a perl script, which can
> > extract .tar files in
> > different directories?
>
> > e.g.
>
> > I have ./data/11/aaa/1a.tar, 1b.tar, 1c.tar
> >          ./data/22/bbb/2a.tar, 2b.tar, 2c.tar
>
> > how can I extract 1*.tar and 2*.tar files under /data directory into a
> > specified folder.
>
> > Since I am pretty new to perl, I dont know how to examine every sub-
> > directory
> > in the ./data, if there are any .tar files, then unzip it.
> > could you give me any examples.
>
> > Thanks a lot!
>
> You can use File::Find to traverse a directory tree. http://
> perldoc.perl.org/File/Find.html
>
> >From perl you can execute any unix command using system("cmd").
>
> Regards,
> Manish

Thanks for all reply, actually, I am running my script in windows XP,
so I can not use unix cmd.




------------------------------

Date: 16 Feb 2007 08:49:14 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: How to extract .tar files in different directory?
Message-Id: <1171644554.628922.239170@q2g2000cwa.googlegroups.com>

On Feb 16, 7:42 am, au.da...@gmail.com wrote:

> Thanks for all reply, actually, I am running my script in windows XP,
> so I can not use unix cmd.

Look  at 7-Zip, which is an open-source app running on Windows that
nicely handles tar, plus other formats.

http://www.7-zip.org/

Wikipedia has lots to say...

http://en.wikipedia.org/wiki/Tar_%28file_format%29



------------------------------

Date: Fri, 16 Feb 2007 17:24:27 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: How to extract .tar files in different directory?
Message-Id: <fNlBh.2809$tD2.167@newsread1.news.pas.earthlink.net>

On 02/16/2007 08:42 AM, au.danji@gmail.com wrote:
> On Feb 15, 4:29 pm, "mar...@gmail.com" <mar...@gmail.com> wrote:
>> [...]
>> From perl you can execute any unix command using system("cmd").
>>
>> Regards,
>> Manish
> 
> Thanks for all reply, actually, I am running my script in windows XP,
> so I can not use unix cmd.
> 
> 

You can install the Perl module Archive::Tar to help you with the tar files.


-- 
Windows Vista and your freedom in conflict:
http://www.regdeveloper.co.uk/2006/10/29/microsoft_vista_eula_analysis/


------------------------------

Date: 16 Feb 2007 12:00:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: pattern serach over many files
Message-Id: <53lkn4F1s6p0sU1@mid.dfncis.de>

Mirco Wahab  <wahab-mail@gmx.de> wrote in comp.lang.perl.misc:
> Mirco Wahab wrote:
> > Change one line
> > ...
> > in order to find lines w/all three occurrences
> 
> BTW, my initial code was more like 'enhanced pseudo Perl',
> so if you are interested to do some more Perl, you should
> adopt to a more robust programming style, you should
> for example (at least) check opened file handles and
> avoid unnecessary  repeated statements, more like:
> 
> [revamped example]
> 
>    use strict;
>    use warnings;
> 
>     my $term = qr/abc/;
>     my @name = qw' file1.txt file2.txt file3.txt ';
> 
>     open my $f1, '<', $name[0] or warn "$name[0] $!";
>     open my $f2, '<', $name[1] or warn "$name[1] $!";;
>     open my $f3, '<', $name[2] or warn "$name[2] $!";;
> 
>     my ($count, $line) = (0, 0);
>     while( ! eof($f1) and ! eof($f2) and ! eof($f3) ) {
>        my @lines = (scalar <$f1>, scalar <$f2>, scalar <$f3>);
>        ++$line;
>        print ++$count, ". # $line\n" if 3 == grep /$term/, @lines;
>     }
> 
>     print "Total: $count\n";

    my @name = map "file$_.txt", 1 .. 3;
    my @fh;
    open $fh[ @fh], '<', $_ for @name;

    while ( ! grep eof( $_), @fh ) {
        chomp( my @lines = map scalar <$_>, @fh);
        # etc...
    }
    # etc...

Anno


------------------------------

Date: Fri, 16 Feb 2007 05:54:35 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: pattern serach over many files
Message-Id: <slrnetb6rr.pqd.tadmc@tadmc30.august.net>

Mirco Wahab <wahab-mail@gmx.de> wrote:
> Tad McClellan wrote:
>> pavan734@gmail.com <pavan734@gmail.com> wrote:
>>> I think you have misunderstood. 
>> No, I think I didn't.
>>> file1 name is file1.txt and `abc',
>>> 'def abc', 'dadq aft', `abc ttsg' are its contents. 
>> Yes, I understood all of that, but I didn't want to litter my
>> filesystem with a bunch of files just for testing.
>> I left it to you to figure out yourself how to read each of
>> the 3 files into an array, or to adapt it to read 3 files
>> in parallel.
>
> I know you wouldn't hesitate to spell out
> a complete solution for all this within 45
> seconds if necessary, but I believe in this
> case your example wasn't really a good one.
>
> I actually tried to start from it and pull
> a solution but there are (imho) some larger
> difficulties from a beginners view because
> you can't really index file lines via
> loop variables.

But since he said we are guaranteed that the files all have
the same number of lines ...

> As one can see, to adopt to a 'file reading solution',
> you have to completely rewrite the loop ... ;-)


 ... the loop can be adopted to reading from files instead of having
the data in arrays without much trouble.


   # assume 3 open()s done here

   while ( my $file1 = <FILE1> ) {
      next if $file1 =~ /abc/;

      my $file2 = <FILE2>;
      next if $file2 =~ /abc/;

      my $file3 = <FILE3>;
      next if $file3 =~ /abc/;

      $cnt++;
   }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 16 Feb 2007 15:35:12 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: pattern serach over many files
Message-Id: <er4fpf$nbh$1@mlucom4.urz.uni-halle.de>

Tad McClellan wrote:
> Mirco Wahab <wahab-mail@gmx.de> wrote:
>> I actually tried to start from it and pull
>> a solution but there are (imho) some larger
>> difficulties from a beginners view because
>> you can't really index file lines via
>> loop variables.
> 
> But since he said we are guaranteed that the files all have
> the same number of lines ...
> ...
> ... the loop can be adopted to reading from files instead of having
> the data in arrays without much trouble.
> 
>    # assume 3 open()s done here
> 
>    while ( my $file1 = <FILE1> ) {
>       next if $file1 =~ /abc/;
> 
>       my $file2 = <FILE2>;
>       next if $file2 =~ /abc/;
> 
>       my $file3 = <FILE3>;
>       next if $file3 =~ /abc/;
> 
>       $cnt++;
>    }

This would imho loose synchronization
(number of read lines in each file).

You need to subsequently read
/one line out of each file/
in every iteration. If you don't,
you'd compare file1's twentieth
line with file2's second or so.

Regards

M.


------------------------------

Date: 16 Feb 2007 06:42:27 -0800
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: pattern serach over many files
Message-Id: <1171636947.358197.217870@q2g2000cwa.googlegroups.com>

On Feb 15, 4:39 am, pavan...@gmail.com wrote:
> On Feb 15, 4:53 pm, Tad McClellan <t...@augustmail.com> wrote:
>
>
>
> > pavan...@gmail.com <pavan...@gmail.com> wrote:
> > > Hi,
> > >      Suppose I have got 3 files like this
>
> > > file1.txt                  file2.txt                  file3.txt
> > > abc                       gsywg                    wrtw
> > > def abc                  abc hshs               dhwu wwg
> > > dadq aft                 hhs gtc                  ffs
> > > abc ttsg                 abc hhshh             abc
>
> > > Assume that all the files are of same no. of lines
>
> > > I need a script that compares each line of all the files for the
> > > pattern "abc" and print the number of lines not containing the pattern
> > > "abc" in all the files
>
> > > In the above example, the script must print 1 because only 3rd line of
> > > all the files is not containing the pattern "abc". I think you
> > > understood my question, if not pls ask me again, I will eloborate more.
>
> > ----------------------
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
>
> > my @file1 = ('abc', 'def abc', 'dadq aft', 'abc ttsg');
> > my @file2 = ('gsywg', 'abc hshs', 'hhs gtc', 'abc hhshh');
> > my @file3 = ('wrtw', 'dhwu wwg', 'ffs', 'abc');
>
> > my $cnt=0;
> > foreach my $i ( 0 .. $#file1 ) {
> >    next if $file1[$i] =~ /abc/;
> >    next if $file2[$i] =~ /abc/;
> >    next if $file3[$i] =~ /abc/;
> >    $cnt++;
>
> > }
>
> > print "$cnt\n";
> > ----------------------
>
> > --
> >     Tad McClellan                          SGML consulting
> >     t...@augustmail.com                   Perl programming
> >     Fort Worth, Texas- Hide quoted text -
>
> > - Show quoted text -
>
> I think you have misunderstood. file1 name is file1.txt and `abc',
> 'def abc', 'dadq aft', `abc ttsg' are its contents. Similarly for
> file2.txt and file3.txt. Note that the contents can be anything and my
> real application files are containing as many as 2000 lines.


Tie::File (comes with Perl distro now) will
load a file into an array for you.  Slower
if big or many files but an easy upfront
change to use Tad's solution.

Eg,

tie @array1, 'Tie::File', 'file1.txt' or die ...;

--
Charles DeRykus



------------------------------

Date: 16 Feb 2007 11:38:03 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Perl takes a lot of memory when you just require a file
Message-Id: <53ljcrF1tji5qU1@mid.dfncis.de>

RJ <jain.nsit@gmail.com> wrote in comp.lang.perl.misc:
> I am decompiling some data from my C code which can be used by Perl
> programs later on. My Data structure is something like follows -
> 
> struct tDs{
> char *tName;
> int *data;
> }
> 
> struct DS{
> int index;
> char *rName;
> <list> tDs;
> }

What's to decompile?  The lines above are (pseudo-) C code.

> I am decompiling above data in a perl file (which  I generate from C
> code) as follows
> 
> <generated_file.pl>
> pass_data_from_perl_to_c (index1,rName,{"tName1" => "data1" , "tName2"
> => "data2"});

Does that mean the generated file contains the line "pass_data_...",
or does it mean the "pass_data_..." function generates the file?

> The last argument in above function call is a hasg referemce to list
> of values associated with various objects of type tDs for index
> index1.

A hash reference isn't a list.

> First of all, if I just do a `require "<generated_file.pl>" ` it takes
> a lot of memory (around 4Mb for 2 Mb file even if I do just a return
> after entering pass_data_from_perl_to_c and populate no Data).
> If I do populate data in form of 3-D array is perl memory requirement
> is 5 times than expected.

Perl often takes more memory than expected.  Adjust your expectations.

> Can someone Please explain me why this is so and how I can avoid
> spending unnecessary memory taken by require.

Since we have not the slightest idea what the generated file contains,
there's no way we can explain its behavior.

> Waiting for a quick reply.

Quick?  You're talking to unpaid volunteers.

Anno


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 144
**************************************


home help back first fref pref prev next nref lref last post