[19729] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1924 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 13 21:05:52 2001

Date: Sat, 13 Oct 2001 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003021507-v10-i1924@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 13 Oct 2001     Volume: 10 Number: 1924

Today's topics:
    Re: $query->param not working. (Martien Verbruggen)
    Re: command line argument <rob_13@excite.com>
    Re: Doing cyclic log files <peterhi@shake.demon.co.uk>
    Re: File test operators can't tell a file from a direct <goldbb2@earthlink.net>
    Re: How do you get paid for Perl work over the Internet <aperlprogrammer@yahoo.com>
    Re: How do you get paid for Perl work over the Internet <tim@vegeta.ath.cx>
    Re: i need help please <rob_13@excite.com>
    Re: Length of last matched substring? <goldbb2@earthlink.net>
    Re: Module help <goldbb2@earthlink.net>
        Perl and Win32 (Darlene Murphy)
    Re: Perl and Win32 <tim@vegeta.ath.cx>
    Re: Perl and Win32 <wsegrave@mindspring.com>
    Re: Perl and Win32 <jeff@vpservices.com>
        PERL freelance programmer availeable (Mark Draper)
    Re: PERL freelance programmer availeable <jeff@vpservices.com>
    Re: Perl on Soalris > need help with install <tintin@snowy.calculus>
    Re: pipe to nawk within perl? <Juha.Laiho@iki.fi>
    Re: pipe to nawk within perl? <tintin@snowy.calculus>
    Re: Reformat Chain (Houda Araj)
    Re: s/([^\n])</\1\n</g what does it means? <matthew.garrish@sympatico.ca>
    Re: Stop Transversal of a Directory with Tar and Unzip <goldbb2@earthlink.net>
    Re: String To List <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Oct 2001 07:44:50 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: $query->param not working.
Message-Id: <slrn9shdei.di2.mgjv@martien.heliotrope.home>

[Please in the future, put your reply _after_ the suitably trimmed text
you reply to. It is the commonly accepted quoting style on this
newsgroup, and Usenet in general] 

On Sat, 13 Oct 2001 12:50:57 +0100,
	Scott Bell <news@scottbell.org> wrote:
> Eric Bohlman <ebohlman@omsdev.com> wrote in message
> news:9q979q$dsu$1@bob.news.rcn.net...
>> Scott Bell <news@scottbell.org> wrote:
>> > I have a simple CGI website, but I get this error:
>>
>> >   Can't call method "param" on an undefined value at
>> > /home/sbell/public_html/index.cgi line 52.
>>
>> > The code thats causing the error is this:
>>
>> >   if ($query->param(content) eq home){
>> >      print "home<br>\n";
>> >   } else {
>> >      print "<a href=\"?\">home</a><br>\n";
>> >   }
>>
>> That means that for whatever reason, $query never got set to anything
>> (either because you made no attempt to set it or your call to CGI's
>> constructor failed for some reason).
>>
> Thanks, I missed out $query = new CGI;

That isn't the only thing wrong with your exampole code though. content
and home on the first line are barewords. While that will work in many
cases, it is a fairly dangerous thing to do in Perl. it'll become buggy
some day, without you realising why.

The best advise I can give you is to start programming perl with
warnings and strictures enabled, and to only disable them when you
really know why you are disabling them. Start all your programs with:

#!/usr/local/bin/perl -w
use strict;

or

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

and all your CGI programs with

#!/usr/local/bin/perl -wT
use strict;

See the perlsec documentation for the meaning of the -T flag.

If you adopt these things, strict and warnings, you will find that Perl
will really help you find about 90% of the bugs that are waiting for
you.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Sat, 13 Oct 2001 18:23:04 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: command line argument
Message-Id: <Xns9139923B6DEC6rock13com@64.8.1.226>

David Hilsee
<news:KeQx7.151523$Xz1.23228480@news1.rdc1.md.home.com>: 
 
> "Rob - Rock13.com":
>> Zimmen Gnauh:
>> > Does perl have anything similar to main(argc, argv) in 
>> > C? How can perl obtain the argv? 
>>
>> I'm not very familiar with C but:
>> prompt> perl script param1
>> $ARGV[1] is now 'param1'

> Strange, you indicate behavior that a C programmer would
> expect.
> In C, argv[0] is the name of the file and argv[1] is
> the first parameter.  In perl, the arguments start at $ARGV[0],
> and the name of the script is in $0. 

:-( Well, I'm rather new to Perl too. Thanks for pointing that out, 
not sure why I got it mixed up.

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Sat, 13 Oct 2001 21:34:16 +0100
From: "Peter Hickman" <peterhi@shake.demon.co.uk>
Subject: Re: Doing cyclic log files
Message-Id: <1003005190.15671.0.nnrp-07.9e980a61@news.demon.co.uk>

I think I am going blind. I looked on CPAN and thought that I found nothing
and so asked here. Now I see there are 3 under Logfile and 12 just for
logging.

Thanks for that

"Ilya Martynov" <ilya@martynov.org> wrote in message
news:87k7y0v9so.fsf@abra.ru...
> >>>>> On Fri, 12 Oct 2001 22:08:36 +0100, "Peter Hickman"
<peterhi@shake.demon.co.uk> said:
>
> PH> Is there a module for doing log files that change daily / weekly /
> PH> monthly / whatever. Or is there a need for one?
>
> Quick search on CPAN reveals one such module: Logfile::Rotate
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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

Date: Sat, 13 Oct 2001 18:20:23 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: File test operators can't tell a file from a directory
Message-Id: <3BC8BE27.9CF9D9D4@earthlink.net>

Eamonn wrote:
> 
> Hi,
> 
> I open a directory and read all the files and sub-directories into an
> array like so :
> _____________________________________________________
> opendir (THISDIR, ".") || die "could not open";
> @topdir = grep { $_ ne '.' and $_ ne '..' and $_ ne 'CVS' } readdir
> THISDIR;
> closedir THISDIR;
> _____________________________________________________
> 
> Then I cycle through the entries in the array to sort the files from
> the directories.  The files are put into another array and the
> directories are examined in the same way.  Every time a directory is
> found it is opened and examined in the same way, the files are put
> into the big file array and the directories are opened and examined.
[snip code]
> Once I get down into the second level of sub-directories, the file
> test operators don't seem to be able to tell the difference between a
> file and a directory.  The scrip begins to treat sub-sub-directories
> as files.  I have tried using -d else treat as a file, tried -f else
> treat as a directory, neither seem to work.  Has anyone else found
> this problem?

First, why your code doesn't work: the items returned by readdir L1DIR
are just the names, without having $entry prefixed to them.  If you were
going to modifiy this code to make it work, you would change the line:
    @thissubdir = grep { $_ ne '.' and $_ ne '..' and $_ ne 'CVS' }
        readdir L1DIR;
To:
    @thissubdir = map "$entry/$_", grep !/^(?:\.\.?|CVS)$/,
        readdir L1DIR;
And similarly, for sub-sub dirs.

However, I would suggest scrapping your code entirely, and replace it
with a File::Find solution:

use File::Find;
find( sub {
    if( $_ eq "CVS" ) { $File::Find::prune = 1; return }
    if( !-f $_ ) { return }
    .... do stuff with $_ or $File::Find::name ....
}, "." );

The .... do stuff ... refers to whatever it is you want to do with your
files.  Print them out, check them in, whatever.

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


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

Date: Sat, 13 Oct 2001 20:07:13 GMT
From: Carlos C. Gonzalez <aperlprogrammer@yahoo.com>
Subject: Re: How do you get paid for Perl work over the Internet??
Message-Id: <MPG.16324c32d15dc0369897b0@news.edmonton.telusplanet.net>

Alan Wrigley at spamhater@keepyourfilthyspamtoyourself.co.uk said...

> And why on earth would anyone pay to commision work that's going to be
> sub-contracted to novices?

Hi Alan.  Though I cannot yet speak from much experience in this I 
believe if one considers programming services as a product being sold to 
customers the principals that make joint-ventures successful will work in 
getting Perl programmers work.

I do the marketing.  I sell the product.  New programmers get to do the 
work.  I would hand off the client to a new programmer lock, stock, and 
barrel.  Getting a small commission only on work that I could not handle 
myself.  Timewise.  I will undoubtedly get more work than I can 
handle eventually and I don't want to just drop potential clients without 
making something in return for my efforts in getting them.  

I believe new programmers could do a lot of the work at lower rates than 
very experienced ones and clients want to save money.  If the work is not 
done according to the clients specs the programmer would simply not get 
paid (and I would not get my commission). 

The programmer undertaking the work will handle it all.  I will be out of 
it once a project is handed over.  I will only be paid (10-15%) if the 
client decides to commission the work from the programmer I handed things 
over to.  And only on a first contract.  Subsequent contracts would be 
totally between the programmer and the client. As such it would be in the 
interests of the programmer to earn a lower than ideal rate per hour on 
the first contract (given my commission cut) in order to secure a 
potentially long term client.  Of their own.  

From a clients perspective they are getting the work at no more than I or 
another beginning programmer might charge.  I am banking on most of them 
not caring that a beginner programmer is doing the work as long as the 
work is done and as long as they are dealing directly with the programmer 
doing the work.  

Most of my clients will not be corporations but rather individuals 
wanting to establish a web presence for themselves at the lowest 
realistic price.  They will not have the time to do it themselves and 
will readily jump I believe on the chance to get beginning programmers to 
do some or all of the work for them at a lower rate.

The bottom line for most of my clients will be getting the job done in a 
resonable period of time, getting the code written so that it works, and 
done as cheaply as possible.  Many individuals simply cannot afford the 
$100.00 per hour rates a lot of programmers charge and that corporations 
are willing to pay.  My focus is to market some kind of solution to 
individuals.  Mom and pop operations.  Not corporate America.  

I believe it will work.  

---
Carlos 
www.internetsuccess.ca (not operational yet)


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

Date: Sat, 13 Oct 2001 21:44:57 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: How do you get paid for Perl work over the Internet??
Message-Id: <slrn9she9f.6hl.tim@vegeta.ath.cx>

Me parece que Carlos C Gonzalez <aperlprogrammer@yahoo.com> dijo:
[ snippage ]
>  Most of my clients will not be corporations but rather individuals 
>  wanting to establish a web presence for themselves at the lowest 
>  realistic price.  They will not have the time to do it themselves and 
>  will readily jump I believe on the chance to get beginning programmers to 
>  do some or all of the work for them at a lower rate.

It seems your hopeful clientele might be better served with GeoCities
HTML interfaces, or perhaps Micro$oft FrontPage.  "Individuals wanting
to establish a web presence for themselves" sounds like your
run-of-the-mill WebTV user, and doesn't bring to mind the vision of
happy, employed, competent, experienced Perl programmers that it
apparently does you.  (Was this thread about Perl at some point?)

Not to mention you're questionable bait-and-switch sales technique, on
top of the fact that you're placing _you're_ reputation in the hands of
new and inexperienced programmers (those willing to work for the rates
you imply).  Besides, by removing yourself after the first cash
exchange, nothing stops the sub-contracted programmer from offering
himself as independent contractor to the client's friends/acquaintances.
Your part in your proposed plan may be short-lived.

[ snip ]

>  I believe it will work.

Well, that's the important thing, I suppose.

>  ---
>  Carlos 
>  www.internetsuccess.ca (not operational yet)

Non-standard sig and defunct web site...a good start.

Best of luck.

-- 
A holding company is a thing where you hand an accomplice
the goods while the policeman searches you.


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

Date: Sat, 13 Oct 2001 18:51:04 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: i need help please
Message-Id: <Xns913996FA4D6F9rock13com@64.8.1.227>

JOSUESAINTVILLIE
<news:20011013094230.28876.00003027@mb-cl.aol.com>: 

[I replied once but messed up the F'up so perhaps the cancel will 
work or perhaps not:-( ]

> i need some help. i am a student in computer science. i am 
studying
> operating system. 

So why ask a Perl group?

> The homework consists of finding data structure used to manage a
> processor. 

I'm not very clear on what you are after. Hm, a processor or a 
process? I think you mean 'process'. 

> he told me to find
> any description of the object. please help me. this homework is  
due
> monday the 15 november 2001 

I guess you better get to work then!

Have you learned about data structures yet? Start with that. You 
have processes, or tasks, lining up to be executed--how should they 
be handled? What order?


-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Sat, 13 Oct 2001 17:59:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Length of last matched substring?
Message-Id: <3BC8B924.3745F81E@earthlink.net>

Bryan K. Wright wrote:
> 
> Hi folks,
> 
>         I'm trying to come up with a regular expression
> involving the length of a previously-matched substring.  What
> I have in mind is something like this:
> 
> $string = "this
> ---";
> undef $/;
> $string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
> 
>         (obviously, this example won't work, since I can't
> just insert the length() call in the regular expression, but
> you get the idea.)
> 
>         It seems like there should be some way to get the LENGTH
> of the last-matched substring, in addition to its value, but
> I haven't found it yet.  Any suggestions?

There is, but it's not what you want.  What you have is an XY problem,
you want to do X, you think that you need Y to do X, and you ask how to
do Y.  You'd be better off asking how to do X.

my $prev;
while( <> ) {
    chomp;
    if( /^[ -]*$/ ) { # we got a line of dashes and spaces.
        $prev .= " " x (length - length $prev);
        print underline( $prev, $_ ), "\n";
        $prev = '';
    } else {
        print $prev, "\n" if defined $prev;
        $prev = $_;
    }
}

sub underline {
    my ($text, $lines) = @_
    my @locations;
    push @locations, [$-[0], $+[0]] while $lines =~ /-+/g;
    while( my $from_to = pop @locations ) {
        substr($text, $from_to->[1], 0, "</u>");
        substr($text, $from_to->[0], 0,  "<u>");
    }
    $text;
}

This code is untested.  Yes, I know it looks a bit like Anno's, but I
think mine is prettier :P  For one thing, it makes more sense [to me,
anway] to use push and pop rather than unshift and shift.  Also, a LoL
makes more sense [to me] than two seperate arrays.

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


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

Date: Sat, 13 Oct 2001 19:21:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Module help
Message-Id: <3BC8CC60.E1B2B489@earthlink.net>

Jessica Bull wrote:
[snip]
> The script is dying when it calls "has_data".  Uninitialized value in
> numeric le (<=)
> Code:
> sub has_data {$_[0]->{row} <= $_[0]->{sheet}->{MaxRow} }

This message "Uninitialized ..." is merely a warning, not an error.  It
should not be causing your code to die.

Oh, and in your earlier code, you should probably replace:
            @data = $sheet->next_row;
With:
            push @data, $sheet->next_row;
[untested]

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


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

Date: 13 Oct 2001 15:15:03 -0700
From: deemurphy_us@yahoo.com (Darlene Murphy)
Subject: Perl and Win32
Message-Id: <dbcc56f5.0110131415.18e14c79@posting.google.com>

I am trying to get perl to run under WinME.  I have done web sites on
unix systems with perl and they work fine.

For WinMe I am using WinSite and ActiveState Perl.  It dose not
recognize #!g:\perl\bin\perl.  What should I use?  Also how do we put
comments in our perl scripts.

I have also tryed on W2K Adv. Server using IIE or IBM's Servers and
ActiveState Perl and get the same results.

#1g:\perl\bin\perl comes up in my window after a submit and then the
rest of the file which is garbage.

Help
Darlene D. Murphy
deemurphy_us@yahoo.com


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

Date: Sat, 13 Oct 2001 22:28:04 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Perl and Win32
Message-Id: <slrn9shgqd.78r.tim@vegeta.ath.cx>

Me parece que Darlene Murphy <deemurphy_us@yahoo.com> dijo:
>  I am trying to get perl to run under WinME.  I have done web sites on
>  unix systems with perl and they work fine.
>  
>  For WinMe I am using WinSite and ActiveState Perl.  It dose not
>  recognize #!g:\perl\bin\perl.  What should I use?  Also how do we put
>  comments in our perl scripts.
>  
>  I have also tryed on W2K Adv. Server using IIE or IBM's Servers and
>  ActiveState Perl and get the same results.
>  
>  #1g:\perl\bin\perl comes up in my window after a submit and then the
>  rest of the file which is garbage.
>  
>  Help
>  Darlene D. Murphy
>  deemurphy_us@yahoo.com

As this has more to do with ActiveState Perl and Win32 than the Perl
langauge at large, you'll probably find help tailored more toward your
needs in the ActiveState mailing lists, notably the Perl-Win32-Web list.

    http://aspn.activestate.com/ASPN/Perl/Mail

Best wishes.
Tim
-- 
How do I type "for i in *.dvi do xdvi i done" in a GUI?
    -- discussion in comp.os.linux.misc


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

Date: Sat, 13 Oct 2001 17:39:18 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Perl and Win32
Message-Id: <9qage7$3vm$1@slb5.atl.mindspring.net>

"Darlene Murphy" <deemurphy_us@yahoo.com> wrote in message
news:dbcc56f5.0110131415.18e14c79@posting.google.com...
> I am trying to get perl to run under WinME.  I have done web sites on
> unix systems with perl and they work fine.
>

You might try IndigoPerl, available as a free download from
http://www.indigostar.com/indigoperl.htm

Bill Segraves
Auburn, AL




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

Date: Sat, 13 Oct 2001 17:57:08 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Perl and Win32
Message-Id: <3BC8E2E4.35084D5A@vpservices.com>

Darlene Murphy wrote:
> 
> I am trying to get perl to run under WinME.   I have done web sites on
> unix systems with perl and they work fine.
> 
> For WinMe I am using WinSite and ActiveState Perl.  It dose not
> recognize #!g:\perl\bin\perl.  What should I use?  Also how do we put
> comments in our perl scripts.

I have no idea what kind of shebang WinSite expects, but you might try
reversing your slashes:  

    #!g:/perl/bin/perl -wT

since forward slashes are fine on windoze for most purposes.  But check
WinSite docs or a server related newsgroup if that doesn't work.
 
> I have also tryed on W2K Adv. Server using IIE or IBM's Servers and
> ActiveState Perl and get the same results.

Off topic bias: when you've tried the rest, try the best:  get apache,
it works fine on winblows too.

> Also how do we put comments in our perl scripts.

The same as on *nix, with the pound sign "#" and, for longer ones, with
=pod and =cut.

-- 
Jeff



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

Date: 13 Oct 2001 16:59:53 -0700
From: cgiprogrammer9932@hotmail.com (Mark Draper)
Subject: PERL freelance programmer availeable
Message-Id: <d73a1bf1.0110131559.412112b6@posting.google.com>

Hello,

I'm flexible and quality oriented with a proven track record of
completing large scale projects ( iqseek.com , slapsearch.com , 
mydotcom.com ).   I'm open to freelance projects and usually deliver a
bid for the total project.  Payment is made upon your %100
satisfaction.  It is my goal to prove my capablities and establish a
long term business relationship. Please feel free to contact me with
any questions.

Looking Forward, 
         Mark Draper


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

Date: Sat, 13 Oct 2001 18:00:00 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: PERL freelance programmer availeable
Message-Id: <3BC8E390.6A40FE77@vpservices.com>

Mark Draper wrote:
> 
> I'm flexible and quality oriented with a proven track record of
> completing large scale projects ( iqseek.com , slapsearch.com ,
> mydotcom.com ).   I'm open to freelance projects and usually deliver a
> bid for the total project.  Payment is made upon your %100
> satisfaction.  It is my goal to prove my capablities and establish a
> long term business relationship. Please feel free to contact me with
> any questions.

You forgot to mention this in your list of qualifications: "ignorant of
and/or rude enough to ignore usenet posting traditions".

Try a newsgroup with "jobs" or "resume" in the title.

-- 
Jeff



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

Date: Sun, 14 Oct 2001 10:41:36 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Perl on Soalris > need help with install
Message-Id: <bc5y7.4$hI6.187452@news.interact.net.au>


"clarke" <nclarke@mindspring.com> wrote in message
news:9pks1f$ja0$1@slb3.atl.mindspring.net...
> Having a hard time installing PERL on Solaris. I download the TAR file and
I
> had problems with the INSTALL file.

And your problems were....?


>
> Can anyone point me in the right direction?

Perl is a piece of cake to compile under Solaris (providing you have a
compiler and tools, of course!).  However, if you don't want to bother with
compiling it, get a packaged version from http://www.sunfreeware.com/





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

Date: 13 Oct 2001 06:52:06 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: pipe to nawk within perl?
Message-Id: <9q8oam$99t$1@ichaos.ichaos-int>

michael.cambray@wellpoint.com (Mike Cambray) said:
>Could anyone out there tell me why I can't get the pipe to nawk
>part of the let2 var below to work (from within a perl script)?
>I want let2 to equal '/u1/letters/033308250.o2540'
>($ssn = '033308250' and $date2grep = 'Sep 11')
>
>$let2 = `ls -l $ld/$ssn.o* | grep '$date2grep' | nawk '{print $9}'`;

The code below is longer than yours, but more efficient, and less prone
to errors caused by odd file names. The efficiency comes primarily from
avoiding execution of external programs (your example above uses at least
four fork/exec pairs to get the results, which is extremely expensive in
terms of computing resources).


$mon2grep=8; $mday2grep=11; # Month numbering runs from zero

opendir(DH,$ld);
while ($fn=readdir(DH)) {
	next if ($fn !~ /^$ssn\.o/s);
	$fn = $ld.'/'.$fn;

	my ($mtime,$mday,$mon);
	$mtime=(stat($fn))[9];
	($mday,$mon)=(localtime($mtime))[3,4];
	if (($mday==$mday2grep) && ($mon==$mon2grep)) {
		print($fn,"\n");
	}
}
closedir(DH);

So, to this you'll still need to add something to convert the date from
'Sep 11' to the corresponding number pair (8,11). Should be easily done
with split and a hash lookup.

The above doesn't assign to anything yet; just prints the results.
You'll get multiple lines if there are multiple files for a given date.
Apparently you'll need something like "push(@files,$fn); in place 
of the "print($fn,..." line to gather all the names to a list.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++$ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Sun, 14 Oct 2001 10:59:57 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: pipe to nawk within perl?
Message-Id: <ku5y7.6$Kj6.85076@news.interact.net.au>


"Mike Cambray" <michael.cambray@wellpoint.com> wrote in message
news:30d612e5.0110121606.17c983e9@posting.google.com...
> Could anyone out there tell me why I can't get the pipe to nawk
> part of the let2 var below to work (from within a perl script)?
> I want let2 to equal '/u1/letters/033308250.o2540'
> ($ssn = '033308250' and $date2grep = 'Sep 11')
>
> $let1 = `ls -l $ld/$ssn.o* | grep '$date2grep'`;
> $let2 = `ls -l $ld/$ssn.o* | grep '$date2grep' | nawk '{print $9}'`;
>
> print "let1 =\n";
> print "$let1\n";
>
> print "let2 =\n";
> print "$let2\n";

Why write a Perl script as a shell script?




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

Date: 13 Oct 2001 12:38:02 -0700
From: Houda.araj@cogmedia.com (Houda Araj)
Subject: Re: Reformat Chain
Message-Id: <36cd2dbf.0110131138.3db96d9b@posting.google.com>

Thomas B?zler <thomas@baetzler.de> wrote in message news:<ssprrtoepe20ie9m63u5a62436mojf26vq@4ax.com>...
> On 5 Oct 2001, houda.araj@cogmedia.com (Houda Araj) wrote:
> 
> >I would like to reformat an (input chain) to an output chain. The
> >input chain has two lines. The first line is plain english words and
> >the second is grammatical categories. What I want to do is to put
> >grammatical label in capital letter after each word.
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my @words = split /\s+/, <DATA>;
> 
> my @notes = split /\s+/, <DATA>;
> 
> print join( ' ', map { $_ . "_" . uc( splice @notes,0,1 ) } @words );
> 
> __DATA__
> cases will be by   means of either the operation of the appropriate
> nns   md/3 be rb/2 vbz/3 in cc     at  nn        in at  jj/2
> 
> HTH,

Hello,
My data should be outsite the script and there are several lines in each file.
The result should be output to a txt file. 
Please help me.

Thanks


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

Date: Sat, 13 Oct 2001 17:34:17 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: s/([^\n])</\1\n</g what does it means?
Message-Id: <Pr2y7.45285$dO3.4160439@news20.bellglobal.com>


"_Mario Latens" <mario.lat@libero.it> wrote in message
news:20011013.171553.1789366143.1838@localhost.localdomain...

> I'm studing perl


Good to see someone is giving their all to propagate the language...

Matt

(just too funny to pass up...)




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

Date: Sat, 13 Oct 2001 16:27:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Stop Transversal of a Directory with Tar and Unzip
Message-Id: <3BC8A39A.99678100@earthlink.net>

What A Man ! wrote:
> 
> Benjamin Goldberg wrote:
> >
> > Randal L. Schwartz wrote:
> > >
> > > >>>>> "BUCK" == BUCK NAKED1 <dennis100@webtv.net> writes:
> > >
> > > BUCK> The strange thing is that if I break the above into more
> > > BUCK> readable lines (below), the -x doesn't work. Any idea why?
> > >
> > > BUCK> `unzip -qjnCL $tmpfile
> > > BUCK>     -x "*\.pl" "*readme*" "*\.ht" "*\.exe"
> > > BUCK>     -d $tmpdir 2>&1`
> > >
> > > Yes, newlines inside of qx// are given as newlines to the shell,
> > > and that's a statement delimiter!
> 
> Thanks Randal.
> 
> > The correct way to do this from within perl would be:
> > unless( fork ) {
> >     open(STDERR, "<&STDOUT") or die "Couldn't dup STDOUT: $!";
> >     exec( "unzip", "-qjnCL", $tmpfile,
> >         qw(-x *.pl *readme* *.ht *.exe),
> >         "-d", $tmpdir );
> >     die "Couldn't exec unzip: $!";
> > }
> 
> Thanks, Ben. I was wondering if this thread even belonged in this
> group, but now with you perl solution, I feel better about that. What
> I really wanted *was* a perl solution, though I didn't express that
> well. Thanks for reading my mind :) and for sticking with me on this.
> 
> A couple of further questions, though. How do I keep your script above
> from giving me an error message if an excluded pattern is not found,
> yet keep the error message if the rest of it fails?

Huh?  I don't see why it should produce an error message if one of the
excluded patterns isn't found.  However, it might be producing an error
message from you using the wrong syntax.  It's possible, even likely,
that the 'exclude list' should be a single argument, with glob patterns
seperated by whitespace, not multiple arguments each with one pattern.

exec( "unzip", "-qjnCL", $tmpfile,
        "-x", "*.pl *readme* *.ht *.exe",
        "-d", $tmpdir );

> ALSO, should I change *exec* to *system* if there is more script below
> the *unzip* portion?

No.  exec() is supposed to *never* return, unless it fails [eg, if it
couldn't find "unzip", or if "unzip" wasn't an executable program].  It
replaces the current process with the one specified by it's arguments. 
That's why it's preceded by a fork() statement.  The fork() splits the
process into parent and child, the parent continues to execute perl, the
child uses exec to transmogrify itself into an instance of unzip.

exec() is sort like perl's magical "goto &subname;" you generally don't
put statements after it because they won't be reached.

> Here is what I'm now testing...
> 
> ### TEST the ZIP File first
> `unzip -qt $tmpfile`;
> if ($? == 0 ) {

Why are you using backticks instead of system()?  This should be:

system("unzip", "-qt", $tmpfile);
if( $? == 0 ) {

For that matter, instead of deeply nesting, you would be better off you
tested for failure, printed error messages, and exitd, than to test for
succeess, and continue, with a further level of nesting an indentation.

if( system("unzip", "-qt", $tmpfile) ) {
    my ($sig, $ret) = ($?&255, $?>>8);
    die "unzip -t died from signal $sig" if $sig;
    die "unzip -t exited with code $ret" if $ret;
    die "system failed: $!";
}
# if we got here, the unzip successfully tested $tmpfile.

> 
> ### UNZIP it
> unless( fork ) {
>   open(STDERR, "<&STDOUT") or die "Couldn't dup STDOUT: $!";
>   exec( "unzip", "-jCLX", $tmpfile,
>       qw(-x *.pl *readme* *.ht *.exe),
>       "-d", $tmpdir );
>   die "Couldn't exec unzip: $!";
>  };
> }

Three comments:  First, in your original code, you used backticks `` to
capture the output of unzip, and then you discarded this output.  So
instead of redirecting stderr to stdout, you probably should close both
stderr and stdout [or open them to dev/null].  Second, even though I
didn't show it, you should always, *always* check the return status of
syscalls, which includes fork().  Third, your parent process probably
ought to wait for it's child [the forked process which is doing the
unzip] to exit, and should *not* just continue running.

defined( my $pid = fork ) or die "Couldn't fork: $!";
if( $pid == 0 ) {
    open(STDOUT, ">/dev/null") or close(STDOUT);
    open(STDERR, ">&STDERR") or close(STDERR);
    # for neither of the above do we really care if we could open
    # /dev/null, since the only purpose of us doing so is to discard
    # our output.
    exec( "unzip", "-qqjnCL", $tmpfile,
            "-x", "*.pl *readme* *.ht *.exe",
            "-d", $tmpdir );
    die "exec(unzip) failed: $!";
}
if( waitpid( $pid, 0 ) ) {
    my ($sig, $ret) = ($?&255, $?>>8);
    die "unzip died from signal $sig" if $sig;
    die "unzip exited with code $ret" if $ret;
} else {
    due "waitpid($pid, 0) failed: $!";
}

> > Note that . is not special inside of a glob, so it does not have to
> > be escaped.
> 
> Thanks for clarifying that. I wasn't sure. Through more testing, I
> also found that that the match pattern for -x will accept a glob
> pattern "read*" or a filename such as "readme".

through testing?  Whatever happened to reading the manual pages?
Even if you don't have access to them on the system you're coding for,
you can get man pages through the web... just do a google search for
"unzip(1)" and it will produce many pages.  There may be some minor
variance from your system, but it's unlikely to be seriously different.

> Unfortunately, I'm stuck using gnu *unzip* and *tar* for awhile until
> I find a new webhost. I had forgot about the thread here several
> months ago where people gave me a Archive::Tar and Archive::Zip
> solution, then I discovered that I couldn't use it, because I needed
> Compress::Zlib and I can't compile on it on my present server.

Can't you get it already compiled for that architecture?

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


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

Date: Sat, 13 Oct 2001 19:16:33 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: String To List
Message-Id: <3BC8CB51.E41E7553@earthlink.net>

Jay wrote:
> 
> Here is what I am trying to do:
> In the sample 4 field text file attached below, I would like to select
> particular lines based on user input, which is a string. What will be
> the better choice for the format of this user string, so that user can
> provide fieldName(s) and fieldValue or fieldName(s) and pattern

The better choice for the format of the user string would be SQL,
because there are modules which will parse it and use it for you.

[snip]
> Text File:
> 
>   field1         field2          field3              field4
> -----------------------------------------------
>   pplus         drawing          14              0
>   cont          drawing           6              0
>   m1            drawing           8              0
>   m1            vss               8              2
>   m1  vdd               8              1
>   via1          drawing          19              0
>   m2            drawing          10              0
>   m2            vss              10              2
>   m2            vdd              10              1
>   via2          drawing          29              0
>   m3            drawing          30              0
>   m3            vss              30              2
>   m3            vdd              30              1
> --------------------------------------------

#!/usr/local/bin/perl -w
use strict;
use DBI;

open( THEFILE, "</foo/bar/thefile" )
    or die "Could not open /foo/bar/thefile: $!";

my $dbi = DBI->connect( "DBI:AnyData" )
    or die $DBI::errstr;

my @fields;
GETFIELDS: {
    defined(local $_ = <THEFILE>) or die "No data in the file!\n";
    redo if /^-*$/;
    @fields = split;
}

$dbi->import( "thetable", "ARRAY", [
    \@fields, map [split], grep !/^-*$/, <THEFILE>
], "ad_import" );

print "Please enter your SQL querys, each terminated by a semicolon\n";
print "Remember, the table is named 'thetable', and the fields are:\n";
print "'", join("', '", @fields), "'\n";
print "Enter an empty statement to exit.\n";

for( my $i = 1; ; ++$i ) {
    print "Query number $i.\n";
    local $/ = ";";
    defined(my $SQL = <STDIN>) or last;
    chomp $SQL;
    last if /^\s*$/;
    unless( my $sth = $dbi->prepare($SQL) ) {
        print STDERR "Invalid SQL query: $DBI::errstr\n";
        next;
    }
    unless( $sth->execute ) {
        print STDERR "Error executing SQL query: $DBI::errstr\n";
        next;
    }
    unless( my $all = $sth->fetchall_arrayref ) {
        print STDERR "Error fetching data: $DBI::errstr\n";
        next;
    }
    my @fields = @{$sth->{NAME}};
    my @lengths = map length, @fields;
    foreach my $row ( @$all ) { for my $col (0..$#fields) {
        $lengths[$col] = length $row->[$col]
            if length $row->[$col] > $lengths[$col];
    } }
    my $format = qq[@{[map "%$_s", @lengths]}\n];
    my $dashes = qq[@{[map "-"x$_, @lengths]}\n];
    printf $format, @fields;
    print $dashes, "\n"
    printf $format, @$_ foreach @$rows;
    print $dashes;
}

__END__

NB: This code is untested.
The output it produces isn't quite the same as it expects for input.

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


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

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.  

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 1924
***************************************


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