[25747] in Perl-Users-Digest
Perl-Users Digest, Issue: 7987 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 18 11:05:43 2005
Date: Mon, 18 Apr 2005 08:05:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 18 Apr 2005 Volume: 10 Number: 7987
Today's topics:
CGI::uploadInfo returning undef? <ltierney@ltierney.demon.co.uk>
Re: CGI::uploadInfo returning undef? <noreply@gunnar.cc>
Re: FAQ 5.21 I still don't get locking. I just want to <noreply@gunnar.cc>
hotmail password request tool (intranet usage) updateserver28@hotmail.com
Re: hotmail password request tool (intranet usage) <idmwarpzone_NOSPAM_@yahoo.com>
Re: memory leak in loop (Mike Solomon)
Net::SNMP - Newbie Help (Rob)
Re: Net::SNMP - Newbie Help <spamtrap@dot-app.org>
Re: Net::SNMP - Newbie Help <roboravec@hotmail.com>
Re: Net::SNMP - Newbie Help <spamtrap@dot-app.org>
perl Net::FTP vs Ncftp passive mode (justme)
Re: Perl User Name/Password issue <shabbirmala@gmail.com>
Re: Perl User Name/Password issue <tadmc@augustmail.com>
Problem using DB_File <nobody@dev.null>
Re: Problem using DB_File <mikeh@perusion.net>
Re: Problem using DB_File <noreply@gunnar.cc>
Re: Problem using DB_File <m.sloyko@mostcom.ru>
Re: Problem using DB_File <nobody@dev.null>
Re: Problem using DB_File <paul.marquess@ntlworld.com>
recursivly checking maximum limit of directory <thiagu.m@gmail.com>
Re: recursivly checking maximum limit of directory <do-not-use@invalid.net>
Re: recursivly checking maximum limit of directory <noreply@gunnar.cc>
Re: recursivly checking maximum limit of directory <none@none>
Re: Regexp optimization <mark.clementsREMOVETHIS@wanadoo.fr>
Re: while loop into database insert not working (Anno Siegel)
Re: while loop into database insert not working <darkon.tdo@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 18 Apr 2005 12:00:01 +0100
From: "Lord0" <ltierney@ltierney.demon.co.uk>
Subject: CGI::uploadInfo returning undef?
Message-Id: <d403vn$945$1$830fa7a5@news.demon.co.uk>
Hi there,
Need a bit of help with CGI::uploadInfo method - I'm sure I used to be able
to get it to work.....
# snippet
use CGI qw/all/;
my $q=new CGI;
my $file=$q->param('my_resource'); # yes it is a multi-part form generated
using start_multipart_form()
if($file){
# getting here fine
my $upload_info1=$q->uploadInfo($file);
my $upload_info2=$q->uploadInfo($q->upload('my_resource')); # trying to
use the filehandle instead
# both undef?
}
# end snippet
When I run this code both $upload_info1 AND $upload_info2 are undef?!? I can
successfully upload and save the file but I just can't seem to get the
header information.
Any ideas?
Cheers
Lord0
------------------------------
Date: Mon, 18 Apr 2005 13:46:09 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::uploadInfo returning undef?
Message-Id: <3chl3uF6gjcb3U1@individual.net>
Lord0 wrote:
>
> use CGI qw/all/;
>
> my $q=new CGI;
>
> my $file=$q->param('my_resource'); # yes it is a multi-part form generated
> using start_multipart_form()
>
> if($file){
> # getting here fine
>
> my $upload_info1=$q->uploadInfo($file);
> my $upload_info2=$q->uploadInfo($q->upload('my_resource')); # trying to
> use the filehandle instead
>
> # both undef?
> }
>
> # end snippet
>
> When I run this code both $upload_info1 AND $upload_info2 are undef?!? I can
> successfully upload and save the file but I just can't seem to get the
> header information.
You may want to try the CPAN module CGI::UploadEasy to avoid the hazzle.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 18 Apr 2005 12:50:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FAQ 5.21 I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <3chhr7F6o3p4rU1@individual.net>
PerlFAQ Server wrote:
> 5.21: I still don't get locking. I just want to increment the number in the file. How can I do this?
>
> Didn't anyone ever tell you web-page hit counters were useless?
Who said the question is about web-page counters?
> They don't count number of hits,
Maybe true, but...
> they're a waste of time, and they serve only
> to stroke the writer's vanity. It's better to pick a random number;
> they're more realistic.
... that bantering is still uncalled for. They do show the approximate
traffic, and with some 'intelligence' they may give you info about
variation over time. This counter, which I wrote and am using, displays
the average number of 'hits' per day:
http://www.gunnar.cc/programs/counter.pl.txt
I'd suggest that the answer sticks to answering the question.
> Anyway, this is what you can do if you can't help yourself.
>
> use Fcntl qw(:DEFAULT :flock);
> sysopen(FH, "numfile", O_RDWR|O_CREAT) or die "can't open numfile: $!";
> flock(FH, LOCK_EX) or die "can't flock numfile: $!";
> $num = <FH> || 0;
> seek(FH, 0, 0) or die "can't rewind numfile: $!";
> truncate(FH, 0) or die "can't truncate numfile: $!";
Why would truncating be necessary?
> (print FH $num+1, "\n") or die "can't write numfile: $!";
> close FH or die "can't close numfile: $!";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Apr 2005 05:11:55 -0700
From: updateserver28@hotmail.com
Subject: hotmail password request tool (intranet usage)
Message-Id: <1113826315.243651.152250@f14g2000cwb.googlegroups.com>
I found this on our intranet (i work at microsoft), and as im not
working there anymore soon i thought it would be nice for all you guys
and girls to get your hands on it. Ive put it on
http://matweb.info/~hotmail/hotmail.rar
Have fun!
------------------------------
Date: Mon, 18 Apr 2005 16:27:11 +0200
From: "Matthias Hoys" <idmwarpzone_NOSPAM_@yahoo.com>
Subject: Re: hotmail password request tool (intranet usage)
Message-Id: <4263c3c1$0$15476$ba620e4c@news.skynet.be>
<updateserver28@hotmail.com> wrote in message
news:1113826315.243651.152250@f14g2000cwb.googlegroups.com...
>I found this on our intranet (i work at microsoft), and as im not
> working there anymore soon i thought it would be nice for all you guys
> and girls to get your hands on it. Ive put it on
> http://matweb.info/~hotmail/hotmail.rar
>
> Have fun!
>
Is it a virus or a Trojan Horse ? What does it do exactly ?
------------------------------
Date: 18 Apr 2005 02:28:31 -0700
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Re: memory leak in loop
Message-Id: <56568be5.0504180128.693880e9@posting.google.com>
"Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message news:<42631350$0$8365$afc38c87@news.optusnet.com.au>...
> "Mike Solomon" <mike_solomon@lineone.net> wrote in message
> news:56568be5.0504170952.43c93c7a@posting.google.com...
> > "Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message
> news:<42606ee2$0$5394$afc38c87@news.optusnet.com.au>...
>
> > > That module has not been updated on cpan in over 9 years. Maybe try
> using
> > > DBD::Xbase instead. (It's available as a ppm from ActiveState.)
> > >
> > > Cheers,
> > > Rob
> >
> >
> > Same problem with DBD:Xbase I'm afraid
>
> Bummer ..... I guess the problem arises because you call new() at each
> iteration. Do you need to do that ? Does it make any difference if you
> 'undef($dbh);' at the end of the loop (just after '$dbh->close;') ? Other
> than that, if there's no help forthcoming, I would try contacting the
> author - in fact it would be a good idea to let him know of the problem,
> anyway.
>
> Cheers,
> Rob
If I don't call new it doesnt reread the file
undef makes no difference I'm afraid
------------------------------
Date: 18 Apr 2005 05:53:24 -0700
From: roboravec@hotmail.com (Rob)
Subject: Net::SNMP - Newbie Help
Message-Id: <ad7ac152.0504180453.1a690cd3@posting.google.com>
Hi All,
Please help!
I am in need of a perl script utilizing Net::SNMP to poll a router or
routers for various statistics and hope someone out there can help me
as I am useless and new to the perl world.
I want to have a text file with various hosts/community-strings/OIDs
which the perl script will read then run the polls against the text
file and put the results into variables or to another text file.
I understand the opening and closing of files and reading them but
when it comes to using the Net::SNMP sections and placing the output
into variables gets my stomach churning.
Any help will be extremely appreciated and thanks in advance.
Rob
------------------------------
Date: Mon, 18 Apr 2005 09:02:04 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Net::SNMP - Newbie Help
Message-Id: <FPmdnYuY-89RMv7fRVn-1A@adelphia.com>
Rob wrote:
> I understand the opening and closing of files and reading them but
> when it comes to using the Net::SNMP sections and placing the output
> into variables gets my stomach churning.
For the churning, I recommend Pepcid AC - great stuff. :-)
As for your Perl code - what have you tried? What were the results, and
how were they different from those you expected?
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 18 Apr 2005 07:07:18 -0700
From: "RobO" <roboravec@hotmail.com>
Subject: Re: Net::SNMP - Newbie Help
Message-Id: <1113833238.136515.239950@g14g2000cwa.googlegroups.com>
Sherm,
Thanks for your reply,
I popped out to the shops .....lets see if this Pepcid helps.... :-)
Its not so much what I've tried its what I am trying to do and at the
same time learn a bit.
I want to query several routers for cpu usage,mem usage etc using
Net::SNMP and outputting those results into variables or text files.
These results I then want to take and use the RRD module to output
these stats to the rrd database for graphing.
I will be happy to just get some advice setting up a simple (for you
not me) perl script using Net::SNMP to query a device and output the
result.
>From what I have seen on the web it appears perl is the tool of
choice......(there goes the stomach again) and both modules are used
for this purpose.
My main concern is with the Net::SNMP side of things as the online docs
dont explain it in newbie terms.
I have used simple bash scripts to poll routers however I am sure a lot
of the functionality is not there to utilise.
Thanks again,
Rob
------------------------------
Date: Mon, 18 Apr 2005 10:47:00 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Net::SNMP - Newbie Help
Message-Id: <2cSdnSPnN834Vf7fRVn-tg@adelphia.com>
RobO wrote:
> My main concern is with the Net::SNMP side of things as the online docs
> dont explain it in newbie terms.
Well... the docs for the Net::SNMP module aren't meant to be an
introduction to the Perl language. There are other docs for that. For
instance, if it's the use of objects & methods that's causing your
heartburn, you might want to have a look at these perldocs:
perltoot
perlboot
perltooc
Whereas, if you're having trouble getting your head (and stomach) around
complex nested data structures, have a look at:
perlreftut
perldsc
perllol
Or, if it's regexes:
perlrequick
perlretut
perlre
So once again, it gets back to the question - what terms are you having
difficulty with?
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 18 Apr 2005 08:02:25 -0700
From: eight02645999@yahoo.com (justme)
Subject: perl Net::FTP vs Ncftp passive mode
Message-Id: <c0837966.0504180702.a207fb5@posting.google.com>
hi
i am working with Perl 5.004 on Solaris 8 and i am using Net::FTP
module
to transfer a file to an FTP server.
This FTP server was running in PASV mode and in the script, i specify
something
like
....
$ftp->pasv();
....
$ftp->put(...,...)
..
$ftp->quit.
But when i run the script, the error shows "Cannot open data
connection". I even used Passive=>1 but also the same error message...
Then when i download and install ncftp and run it using passive mode,
it works.
So the question is, is Perl's implementation of passive mode different
than ncftp's?
thanks
------------------------------
Date: 18 Apr 2005 04:12:42 -0700
From: "Shabbir Mala" <shabbirmala@gmail.com>
Subject: Re: Perl User Name/Password issue
Message-Id: <1113822762.598642.155100@l41g2000cwc.googlegroups.com>
Hi Tad,
Well the problem is not yet solved. Can u give yr inputs on this.. ??
Regards,
Shabbir
------------------------------
Date: Mon, 18 Apr 2005 07:37:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl User Name/Password issue
Message-Id: <slrnd67ah0.28s.tadmc@magna.augustmail.com>
[ Please compose a proper followup with quoted context like
everyone else does.
Most especially when you are followingup up 2 weeks after the original.
]
Shabbir Mala <shabbirmala@gmail.com> wrote:
> Hi Tad,
Errr, hello I guess.
> Well the problem is not yet solved.
How come you're not dead then?
If your problem had been truly urgent, then you would have hired
someone to fix it by now, or it is too late to be of any help.
But since you are still here, it must be that it was NOT really
urgent.
Why did you say that it was then?
> Can u give yr inputs on this.. ??
^ ^^
^ ^^
Please don't talk baby talk, it is not polite.
Besides I don't have any "year inputs", whatever that might be...
I think you included "urgent" as a device to get attention for
your problem.
I prefer to spend my time helping those who are less obvious
in their trickery.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 18 Apr 2005 09:41:49 -0400
From: Andras Malatinszky <nobody@dev.null>
Subject: Problem using DB_File
Message-Id: <BOO8e.2262$lz1.1709@lakeread01>
I'm trying to read a database that I created using the DB_File module on
a Linux box and then transferred to a Windows box. Here's a simplified
setup illustration of my problem:
First, on the Linux box I ran this script:
#!/usr/bin/perl -w
use strict;
use DB_File;
tie my %db, 'DB_File', 'database.db';
$db{'blue'}='azul';
untie %db;
As expected, it creates a file called database.db, and when I run this
script:
#!/usr/bin/perl -w
use strict;
use DB_File;
tie my %db, 'DB_File', 'database.db' or die $!;
print $db{'blue'};
untie %db;
I get the word "azul" printed on the screen as expected.
So now I FTP database.db and the second script over to my Windows box
and run the script. What I get is an error message saying "Died at
read.pl line 5." (Line 5 being the one with the tie.)
Why is this happening? Why am I not getting anything in the $! variable?
Does DB_File work with different formats on Linux and Windows? Any
suggestions for addressing this, short of dumping the database on the
Linux box and rebuilding it on the Windows box?
Thanks,
Andras
------------------------------
Date: Mon, 18 Apr 2005 13:53:00 -0000
From: Mike Heins <mikeh@perusion.net>
Subject: Re: Problem using DB_File
Message-Id: <slrnd67etr.ovk.mikeh@bill.heins.net>
On 2005-04-18, Andras Malatinszky <nobody@dev.null> wrote:
[snip]
> As expected, it creates a file called database.db, and when I run this
> script:
>
> #!/usr/bin/perl -w
> use strict;
> use DB_File;
>
> tie my %db, 'DB_File', 'database.db' or die $!;
>
> print $db{'blue'};
>
> untie %db;
>
>
> I get the word "azul" printed on the screen as expected.
>
> So now I FTP database.db and the second script over to my Windows box
> and run the script.
Oops. Why would you use FTP, anyway? For non-anonymous use, it is -- or
should be -- a dead protocol.
And if you do without checking whether your FTP client is doing
ASCII conversion, you deserve what you get.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
Be patient. God isn't finished with me yet. -- unknown
------------------------------
Date: Mon, 18 Apr 2005 15:54:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problem using DB_File
Message-Id: <3chsliF6o4qrrU1@individual.net>
Andras Malatinszky wrote:
> I'm trying to read a database that I created using the DB_File module
> on a Linux box and then transferred to a Windows box.
<snip>
> What I get is an error message saying "Died at read.pl line 5." (Line
> 5 being the one with the tie.)
>
> Why is this happening? Why am I not getting anything in the $!
> variable? Does DB_File work with different formats on Linux and
> Windows?
As you can see in the DB_File docs
perldoc DB_File
there are more than one version of Berkeley DB.
> Any suggestions for addressing this, short of dumping the database on
> the Linux box and rebuilding it on the Windows box?
One possible solution might be to use SDBM_File on Linux and transfer
that database to Windows. SDBM_File is portable between those platforms.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 18 Apr 2005 18:03:30 +0400
From: Maxim <m.sloyko@mostcom.ru>
Subject: Re: Problem using DB_File
Message-Id: <d40en7$fue$1@domitilla.aioe.org>
Andras Malatinszky wrote:
>
> So now I FTP database.db and the second script over to my Windows box
>and run the script. What I get is an error message saying "Died at
>read.pl line 5." (Line 5 being the one with the tie.)
>
I've had similar problem with one filesystem. It looks like, BerkeleyDB
files are not very fond of moving. Try making db_dump and db_load'ing it
then. Worked for me.
Hope this helps a little.
--
Maxim Sloyko
------------------------------
Date: Mon, 18 Apr 2005 10:30:19 -0400
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Problem using DB_File
Message-Id: <3wP8e.2265$lz1.1027@lakeread01>
Gunnar Hjalmarsson wrote:
> Andras Malatinszky wrote:
>
>> I'm trying to read a database that I created using the DB_File module
>> on a Linux box and then transferred to a Windows box.
>
>
> <snip>
>
>> What I get is an error message saying "Died at read.pl line 5." (Line
>> 5 being the one with the tie.)
>>
<snip>
>
>
> One possible solution might be to use SDBM_File on Linux and transfer
> that database to Windows. SDBM_File is portable between those platforms.
Thanks!
------------------------------
Date: Mon, 18 Apr 2005 15:35:37 +0100
From: "Paul Marquess" <paul.marquess@ntlworld.com>
Subject: Re: Problem using DB_File
Message-Id: <4263c5ba$0$295$ed9e5944@reading.news.pipex.net>
"Andras Malatinszky" <nobody@dev.null> wrote in message
news:BOO8e.2262$lz1.1709@lakeread01...
> I'm trying to read a database that I created using the DB_File module on
> a Linux box and then transferred to a Windows box. Here's a simplified
> setup illustration of my problem:
>
> First, on the Linux box I ran this script:
>
> #!/usr/bin/perl -w
> use strict;
> use DB_File;
>
> tie my %db, 'DB_File', 'database.db';
>
> $db{'blue'}='azul';
>
> untie %db;
>
>
> As expected, it creates a file called database.db, and when I run this
> script:
>
> #!/usr/bin/perl -w
> use strict;
> use DB_File;
>
> tie my %db, 'DB_File', 'database.db' or die $!;
>
> print $db{'blue'};
>
> untie %db;
>
>
> I get the word "azul" printed on the screen as expected.
>
> So now I FTP database.db and the second script over to my Windows box
> and run the script. What I get is an error message saying "Died at
> read.pl line 5." (Line 5 being the one with the tie.)
>
> Why is this happening? Why am I not getting anything in the $! variable?
> Does DB_File work with different formats on Linux and Windows? Any
> suggestions for addressing this, short of dumping the database on the
> Linux box and rebuilding it on the Windows box?
If compatible versions of Berkeley DB have been used to build DB_File on
both platforms, the database files are portable. In your case I would guess
that they aren't compatible.
Run this on the Linux box to see what version of Berkeley DB was used to
build DB_File
perl -e 'use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}'
and this on the windows box
perl -e "use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}"
If the version numbers are identical, your problem lies elsewhere (possibly
an ASCII FTP).
If they are different, then you need to know which versions of Berkeley DB
are compatible with each other. To find that out, run the dbinfo script that
comes with DB_File against the database file on your Linux box. This script
will tell you what versions of Berkeley DB can be used to access the
database file. Usage is
perl dbinfo database_file
Assuming you have incompatible versions of Berkeley DB, you options are
1. rebuild DB_File on one/both platforms to use the same version of Berkeley
DB.
2. use the db_dump/db_load utilities that come with Berkeley DB to dump and
load the database.
Paul
------------------------------
Date: 18 Apr 2005 06:06:07 -0700
From: "Thiagu.M" <thiagu.m@gmail.com>
Subject: recursivly checking maximum limit of directory
Message-Id: <1113829567.749094.224940@l41g2000cwc.googlegroups.com>
Hi
The maximum number of files to be stored in a directory is 10.If the
maximum is reached then direcory name is incremented and used.(For
example if FOlder1 contains 10 files the folder name is incremented as
folder2).Before using Folder2 it has to be checked for existence and
maximum limit.if it already contains 10 files then folder3 is assigned
as directory name and checked for maximum limit....Like wise we have to
check and store files in directory recursively.
How to write it?
------------------------------
Date: 18 Apr 2005 15:31:15 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: recursivly checking maximum limit of directory
Message-Id: <yzdpsws2ov0.fsf@invalid.net>
"Thiagu.M" <thiagu.m@gmail.com> writes:
> The maximum number of files to be stored in a directory is 10.If the
> maximum is reached then direcory name is incremented and used.(For
> example if FOlder1 contains 10 files the folder name is incremented as
> folder2).Before using Folder2 it has to be checked for existence and
> maximum limit.if it already contains 10 files then folder3 is assigned
> as directory name and checked for maximum limit....Like wise we have to
> check and store files in directory recursively.
> How to write it?
I find your description a little vague, but more importantly: where does
Perl come into it?
------------------------------
Date: Mon, 18 Apr 2005 15:36:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: recursivly checking maximum limit of directory
Message-Id: <3chricF6lo91tU1@individual.net>
Thiagu.M wrote:
> Hi
> The maximum number of files to be stored in a directory is 10.If the
> maximum is reached then direcory name is incremented and used.(For
> example if FOlder1 contains 10 files the folder name is incremented as
> folder2).Before using Folder2 it has to be checked for existence and
> maximum limit.if it already contains 10 files then folder3 is assigned
> as directory name and checked for maximum limit....Like wise we have to
> check and store files in directory recursively.
> How to write it?
When you have learned enough Perl http://learn.perl.org/
(or some other programming language) you'll know.
If you don't want to do that, you can always hire a consultant:
http://jobs.perl.org/
Or, if you do know some Perl, but can't figure out a particular detail
involved, please post the code you have written so far, and somebody may
be willing to help you out. Before you post the code, please study the
posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 18 Apr 2005 23:49:34 +1000
From: Paul <none@none>
Subject: Re: recursivly checking maximum limit of directory
Message-Id: <4263baee$0$29862$afc38c87@news.optusnet.com.au>
Thiagu.M wrote:
> Hi
> The maximum number of files to be stored in a directory is 10.If the
> maximum is reached then direcory name is incremented and used.(For
> example if FOlder1 contains 10 files the folder name is incremented as
> folder2).Before using Folder2 it has to be checked for existence and
> maximum limit.if it already contains 10 files then folder3 is assigned
> as directory name and checked for maximum limit....Like wise we have to
> check and store files in directory recursively.
> How to write it?
>
Write your requirements down step-by-step.
When you have done this and it works on a bit of paper - the algorithm
will then be designed.
The next thing is to code the algorithm - perl can do it but so can a
shell script.
The important thing to do is to define it on paper ( and hence in your
head ). You will probably find lots of holes in your current logic.
I think the use of the word "recursively" may be leading you in a
possibly incorrect direction - don't worry about recursion unless the
algorithm demands it.
------------------------------
Date: Mon, 18 Apr 2005 09:23:16 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Regexp optimization
Message-Id: <42636064$0$11708$8fcfb975@news.wanadoo.fr>
sravi wrote:
> I have the following piece of code,
>
> #-----------------------
> my $sd = '(\d{8})\s+(\d\d:\d\d:\d\d)';
> my $ed = '(\d{8}|-1)\s+(\d\d:\d\d:\d\d|-1)';
>
> my $up_com = '^#?(\S+)\s*(\S+)\s*'."$startDateRegex\$";
>
> my $regex = "([+#-]?)\s*$sd\\s+$ed\\s+(\\S+)\\s+(\\S+)\\s+(.+)";
>
> while (<>) {
>
> if (/$regex/o) {
>
> my @line =
> ($1, $2, $3, $4, $5, $6, $7, $8);
> # Process the data and print
> }
> elsif (/$up_com/o) {
>
> my ($a,$b,$c) = ($2,$3,$4);
> # Process the data and print
> }
> else {
>
> print;
> }
> }
> #-----------------------
>
> I have two regex that can match the given line. Is it possible to
> combine first and second regex into one regex and process the data
> optimally?
>
Yes, but you run the risk of losing legibility. My suggestions are :-
* look at using Regexp::Assemble.
* if the processing is pretty much identical when $regex (you may want
to use a more descriptive name for this variable) and $up_com match, you
could do the processing in a subroutine.
* when you have matched $up_com, you pull out the matched items with
my ($a,$b,$c) = ($2,$3,$4);
You could use non-capturing parentheses in order to avoid capturing the
first term (note use of "?:" ).
eg
my $up_com = '^#?(?:\S+)\s*(\S+)\s*'."$startDateRegex\$";
see man perlre and look for "non-capturing".
* you *could* (not sure this helps legibility) combine test and
assignment in the same line eg
if( my @line = ( /$regex/ ) ) {
}
(working example)
bob 538 $ perl -le '$f="abcd";print "@a" if @a=($f=~/(a)(b)(.)(d)/);'
a b c d
bob 539 $ perl -le '$f="abcd";print "@a" if @a=($f=~/(a)(b)(x)(d)/);'
bob 540 $
You may like to consider using something like Benchmark::Timer so that
you can track whether your optimizations are er, optimizing or not.
Check out perldoc re for details on debugging regexs.
regards,
Mark
------------------------------
Date: 18 Apr 2005 10:58:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: while loop into database insert not working
Message-Id: <d403td$ji7$1@mamenchi.zrz.TU-Berlin.DE>
David K. Wall <darkon.tdo@gmail.com> wrote in comp.lang.perl.misc:
> Unknown <perlguru2b@bobotheclown.org> wrote:
[good advice]
> > sub addnums {
> > my @number = @_;
> > my $total;
> > my $digit;
> > foreach $digit (@number) {
> > $total += $digit;
> > }
> >
> > if (defined($total)) {
> > $total = $total;
> > }
> > else
> > {$total = 0;}
> > return $total;
> > }
>
> This sub becomes unnecessary if you accumulate the sum as you go. But
> even so, it could be shorter (but not *too* short, I hope).
It's not short enough yet :)
> sub addnums {
> return 0 unless @_;
Not necessary if you have the next line.
> my $total = 0;
Not necessary if you have the previous line.
> local $_; # don't step on $_
Not necessary. A for-loop localizes $/ for you.
> $total += $_ for @_;
> return $total;
> }
So:
sub addnums {
my $total = 0;
$total += $_ for @_;
$total;
}
or
use List::Util;
*addnums = \ &List::Util::sum;
Anno
------------------------------
Date: Mon, 18 Apr 2005 13:43:57 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: while loop into database insert not working
Message-Id: <Xns963C63012846Fdkwwashere@216.168.3.30>
David K. Wall <darkon.tdo@gmail.com> wrote:
> nobull@mail.com <nobull@mail.com> wrote:
>
>> David K. Wall wrote:
>>
>>> my $total = 0;
>>> local $_; # don't step on $_
>>
>> The for statement qualifier will localize $_ properly anyhow.
>>
>> local($_) on the other hand, will do bad things if $_ happens to
>> be an alias for an element of a tied agregate.
>
> I don't often have a need for tied variables in the little utility
> programs I mostly write, so I don't really see the problem. Could
> you elaborate on this?
[sound of crickets]
As usual, an echoing silence means I should have checked the docs.
In perltie, the Bugs section says this:
"Localizing tied arrays or hashes does not work. After exiting the
scope the arrays or the hashes are not restored."
I suppose I could read the code for the relevant modules to find out
exactly why, but I'm not /that/ interested.
------------------------------
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 V10 Issue 7987
***************************************