[7754] in Perl-Users-Digest
Perl-Users Digest, Issue: 1379 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 27 19:07:25 1997
Date: Thu, 27 Nov 97 16:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 27 Nov 1997 Volume: 8 Number: 1379
Today's topics:
Re: Can I do $! = 'string' ? (Faust Gertz)
Extra Spaces & MSIE unlisted@internet.com
Re: For the pro's ? repost: Leaving HTML tags alone (Jim Michael)
Re: For the pro's ? repost: Leaving HTML tags alone (Patrick)
Re: form results to both email and text file (Eric Hilding)
Re: Formatting Decimals.. (William R. Ward)
Re: Got to be a cleaner Way (E.None Archibald)
Re: How to directly call a POST method <jaydee@worsdall.demon.co.uk>
Re: How To Test if number is ODD or EVEN? (brian d foy)
Re: last element in an array? <ajohnson@gpu.srv.ualberta.ca>
Re: last element in an array? (Jason Costomiris)
Re: Not a programming problem... (E.None Archibald)
Re: old regular expression question <eedmim@eed.ericsson.se>
Re: perl development package ? <kermit@ticnet.com>
Re: PERL Hourly Rates <stevenjm@olywa.net>
Re: PERL Hourly Rates (brian d foy)
Re: PERL Hourly Rates (brian d foy)
Re: Perl/UNIX question (Tad McClellan)
Re: readdir() and Win32 Perl (Shawn Wagner)
Re: regexp problem (Tushar Samant)
Re: Removing Files older than 14 days <jaydee@worsdall.demon.co.uk>
script refuses to print variables to file but happily d (Hel's Synic)
Re: Strange 'print Location:' problem with Perl <tdgilman@DELETETHISbest.com>
Re: Strange 'print Location:' problem with Perl <tdgilman@DELETETHISbest.com>
Re: strange problem with regular expression memory vari <$_=qq!fearless\@NOSPAMio.com!;y/[A-Z]//d>
Re: sytem command test (brian d foy)
truncating a string <wile@inficad.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Nov 1997 22:35:54 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Can I do $! = 'string' ?
Message-Id: <347f9b13.14362503@news.wwa.com>
On 26 Nov 1997 19:31:23 +0100, Marek.Rouchal@hl.siemens.de (Marek
Rouchal) wrote:
>I'd like to set the error message in a module, in a way that
>the caller can do:
>
>die "Error occurred: $!\n" unless(&my_module_function);
>
>( &my_module_function returns undef on failure and sets(?) $! )
>
>The manual says that $! can take only numerical values; on the
>other hand, $! contains error messages when evaluated in a string
>context. Is it possible to assign error messages to $! somehow?
Let's look at perlvar.
:$OS_ERROR
:$ERRNO
:$!
: If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that
: you shouldn't depend on the value of ``$!'' to be anything in particular unless you've gotten a specific error
: return indicating a system error.) If used in a string context, yields the corresponding system error string.
: You can assign to ``$!'' to set errno if, for instance, you want ``$!'' to return the string for error n, or you
: want to set the exit value for the die operator. (Mnemonic: What just went bang?)
It would seem that you can assign a particular error message to $!,
but only by assigning it the number of a system call error. For
example:
1 = Not owner
2 = No such file or directory
3 = No such process
4 = Interrupted system call
5 = I/O error
6 = No such device or address
7 = Arg list too long
8 = Exec format error
9 = Bad file number
10 = No child processes
You can probably collect 'em all by running the following untested
script.
#!/usr/local/bin/perl
$! = $_ = 1;
while ("$_" ne "$!") {
print "$_ = $!\n";
$!++;
$_++;
}
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
------------------------------
Date: Wed, 26 Nov 1997 22:03:35 GMT
From: unlisted@internet.com
Subject: Extra Spaces & MSIE
Message-Id: <347c9b36.117493031@news.chickasaw.com>
I have a small script that prints out a webpage based on a
flatfile database unfortunetly the database contains a few extra
spaces here and there and it is constantly changing so I can't
reformat it so here is my problem, when I generate the html I get an
extra space or two between fields and MSIE puts a %20 in there when it
is passed back to the server. Ex:
Field1&&Field2&&Field3
Page generates from field2...
<A Href=test.cgi?Field2=0=20>Go there</A>
the problem is if there is a space in there then the link becomes
Field2%20=0=20
so.... is there someway I can remove extra spaces from the field
before it is generated by the webpage by using a
$Field2 = tr (something)?
------------------------------
Date: Wed, 26 Nov 1997 22:17:03 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: For the pro's ? repost: Leaving HTML tags alone
Message-Id: <genepoolEK9xwF.CG5@netcom.com>
Patrick (Venice@euronet.nl) wrote:
: Http is a cool protocol, more info at: <A
: HREF="http://www.fictional.net>This http site</A>
: I want to replace 'http' (NOT in the HTML-code) in the above with the
: full name: Hyper Text Transfer Protocol without changing the http://
: in the html tag...
: Or with other words: Replacements without touching things between <>
The particular case appears solvable with a simple substitution:
$myString =~ s/([^"]?)http/$1Hyper Text Transfer Protocol/ig;
providing http within the tag is always preceded by " and http is never
preceded by " outside the tag.
Cheers,
Jim
------------------------------
Date: Thu, 27 Nov 1997 17:19:54 GMT
From: Venice @ euronet.nl (Patrick)
Subject: Re: For the pro's ? repost: Leaving HTML tags alone
Message-Id: <65jaiu$3cr$1@news.NL.net>
scribble@shoga.wwa.com (Tushar Samant) wrote:
><http://www.perl.org/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz>
>2. Take the first two patterns in it (comments and tags), stick a
> "|" between them and parentheses around them, split the HTML on
> the pattern, apply your substitution to every even-indexed element,
> join 'em up with "".
>Note: I haven't tested this.
Thanx, Probably have to solve it with a this. I will take a look at
the strip script.
Where is that one-line-of-perl solution "they" talk about ;-)
Patrick
------------------------------
Date: 27 Nov 1997 08:07:23 GMT
From: eric@garlic.com (Eric Hilding)
Subject: Re: form results to both email and text file
Message-Id: <65j9nr$dau$1@bulb.garlic.com>
dwexler@zeusnet.com wrote:
: I am looking for a script that can send form results to both a comma
: delimited text file and to an email address. This is for a UNIX server.
: Any suggestions?
I can help with part of this...the following are subroutines I've
incorporated into a generic CGI HTML parsing script.
Due to the way some database programs handle ascii csv files, this
version has a 'header' type file with the field names as the first
line each time the file is (re)created. Since it gets added to as
web form entries are processed, and then deleted upon download to
the PC for importing into a forms program, the 1st subroutine checks
for existence of the file before writing, and creates the field name
header junk if the file ain't there :-)
Ummh, the field names correspond to the weird way the PC forms program
works so I can take advantage of an "autolink" feature (this had to
all be done backwards after the fact...but IT WORKS!)...on a Unix/AIX.
&preasciidb; # Many lines of code to format data into field variables
open(FILE ,">>/u/userdir/filename.txt");
print FILE "_18,_19,_20,_23,_25,_26,_27,_28,_29,
_30,_31,_32,_33,_34,_35,_36,_40,_47,_48,_49,_50,
_51,_52,_63,_65,_71,_72,_73\r\n"
if (-z "/u/userdir/filename.txt");
&textdbascii; # All the field info into ascii csv format for download
###############
sub textdbascii {
print FILE "\"$t18\",\"$t19\",\"$t20\",\"$t23\",\"$t25\",\"$t26\",";
print FILE "\"$t27\",\"$t28\",\"$t29\",\"$t30\",\"$t31\",\"$t32\",";
print FILE "\"$t33\",\"$t34\",\"$t35\",\"$t36\",\"$t40\",\"$t47\",";
print FILE "\"$t48\",\"$t49\",\"$t50\",\"$t51\",\"$t52\",\"$t63\",";
print FILE "\"$t65\",\"$t71\",\"$t72\",\"$t73\"\r\n";
}
close(FILE);
Happy Thanksgiving...and T-h-a-n-k-s to all who have helped me with
some of my perl problems in the past!
Eric Hilding
------------
------------------------------
Date: 26 Nov 1997 13:23:26 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Formatting Decimals..
Message-Id: <waaaferqrht.fsf@ese.UCSC.EDU>
Ryan Rose <ryanr@poolpros.com> writes:
> Sorry for the simple question.. could not find it in my books..
>
> Can someone tell me how to format decimal values so I can either pad the
> front, or require 2 places after the decimal point?
>
> I am trying to format out currency correctly.
>
> ie $4.677 would be $4.68
I have written a Perl module called Number::Format that would do this
and a lot more. See my earlier post mentioning it, or ftp to
ftp.bayview.com/pub/perl and download it. Note that this is
pre-released software and may change significantly before it's
announced officially and uploaded to CPAN.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
------------------------------
Date: 26 Nov 1997 20:42:48 GMT
From: yevgene@xochi.tezcat.com (E.None Archibald)
Subject: Re: Got to be a cleaner Way
Message-Id: <65i1k8$dhf$2@tepe.tezcat.com>
randy.paries@avex.com wrote:
: Hello ,
: I have a string that looks like
: -rw-r--r-- 1 2300 2300 1658 Oct 14 06:00 interse_log.971014
: I want to do a @f = split / /g,$str
: the problem is that I have multiple spaces @ a time, and it is unknow how
: many there may be.
man perlfunc
read the entry for split carefully.
the answer to your question is clearly stated there.
--eugene
------------------------------
Date: Thu, 27 Nov 1997 03:29:47 +0000
From: Mark Worsdall <jaydee@worsdall.demon.co.uk>
Subject: Re: How to directly call a POST method
Message-Id: <VoioaUArkOf0Ewx6@worsdall.demon.co.uk>
><form method=POST action="http://www.domain.com/cgi-bin/test.pl">
> <input type=text name=var size=6><BR><BR>
> <input type=submit>
> </form>
>
>Now I want to call test.pl directly without any user action
>(no klicking on the submit button) with a specified value for
>var. How can I do this?
>
2 Methods are availble to you, the preferable is if you have SSI then
you would do this and rename the web extension with .stm
1) SSI Solution:-
<!--#exec cmd="/usr/www/foobar/cgi-bin/test.pl"-->
The other methid if you do not have SSI is to call the script as an
image, bearing in mind that the browser user might have load images
turned off!
2) Image solution
<img src="http://www.domain.com/cgi-bin/test.pl" align=left width=1
height=1 border=0>
The user will not see anyting but the script will be executed, Beware
the script should have a referer checking capability so if oher users
try to hack or call from their pages to script will die.
--
Mark Worsdall - Oh no, I've run out of underpants :(
Home:- jaydeeATworsdall.demon.co.uk WEB site:- http://www.worsdall.demon.co.uk
Shadow:- webmasterATshadow.org.uk WEB site:- http://www.shadow.org.uk
------------------------------
Date: Wed, 26 Nov 1997 21:39:14 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How To Test if number is ODD or EVEN?
Message-Id: <comdog-ya02408000R2611972139140001@news.panix.com>
In article <65a0bb$7ma@dec.cuug.ab.ca>, branderr@cuug.ab.ca (Roy Brander) wrote:
>Ken Fox (fox@pt0204.pto.ford.com) wrote:
>: jay@dixonssurgical.co.uk (Jay Dixon) writes:
>: > I want to test if a variable is Odd (or Even)
>:
>: As inspired by abigail:
>:
>: perl -wle 'print "Even" if (1 x shift) =~ /^(1+?)\1$/'
>:
>
>It's now official. I will never be a perl guru. I've been
>staring at that one for a minute and still can't figure it.
it's a bit more obvious if you talk yourself through some sample input:
sample input = 1
then 1 x 1 gives "1". does "1" match (1+?)\1 ? no, because there is
only one "1" when you need at least two.
aha!
there have to be two identical fragments - the stuff matched by (1+?) has
to also be matched by \1. if the first part has an odd nunber of "1"s,
then so does the second part, which means the overall string had an
*Even* number of "1"s. same if both fragments had an even number of "1"s
if the string had an even number of ones, then whatever was shift()-ed
must have been Even.
and so on...
i don't think this rules out future Guru status though :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 26 Nov 1997 21:50:57 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: last element in an array?
Message-Id: <347CEE21.77702C74@gpu.srv.ualberta.ca>
Jason Costomiris wrote:
!
[snip]
!
! If you have an array, say @foo, then $#foo is the index of the highest
! numbered element in the array. Ex:
!
! my @foo = (1,2,3,4,5,'abc','bar');
!
! $foo[$#foo] is 'bar'.
$foo[-1] is a handy alternative as well...shorter too :-)
regards
andrew
------------------------------
Date: 26 Nov 1997 23:06:52 GMT
From: jcostom@shaft.sjis.com (Jason Costomiris)
Subject: Re: last element in an array?
Message-Id: <slrn67pasb.tts.jcostom@dogbert.sjis.com>
On Tue, 25 Nov 1997 22:38:41 -0500, ,
snailgem@aol.com <,snailgem@aol.com> wrote:
: @matches=grep (/line\d_/, @myfile);
: and
: $nu_matches=grep (/line\d_/, @myfile);
: how do I reference the last element of @matches? ($matches[$nu_matches]
: doesn't work).
:
: Or am I going the wrong way about all this?
If you have an array, say @foo, then $#foo is the index of the highest
numbered element in the array. Ex:
my @foo = (1,2,3,4,5,'abc','bar');
$foo[$#foo] is 'bar'.
--
Jason Costomiris <>< | "VMS is about as secure as a poodle
jcostom@sjis.com | encased in a block of lucite....
http://www.jasons.org/~jcostom/ | .... about as useful, too."
#include <disclaimer.h> | --some guy I read on Usenet
------------------------------
Date: 26 Nov 1997 20:33:34 GMT
From: yevgene@xochi.tezcat.com (E.None Archibald)
Subject: Re: Not a programming problem...
Message-Id: <65i12u$dhf$1@tepe.tezcat.com>
Xavier Canehan <Xavier.Canehan@in2p3.fr> wrote:
: I have just discovered Perl and I'm already fond of it !
: But I have a TERRIBLE question : why is there a camel or a llama on the
: frontpage of the books ?
Read the Colophon, in the back of the book(s).
--eugene
------------------------------
Date: Thu, 27 Nov 1997 09:33:11 +0100
From: Michael Mertens <eedmim@eed.ericsson.se>
Subject: Re: old regular expression question
Message-Id: <347D3047.5E9B@eed.ericsson.se>
Ian Goldstein wrote:
>
> I know this was covered before... but it escapes me.
>
> I have a variable with 6 digits . I want to split this into 2 variables
> of 3 digits each.
> $var=123456;
> ($var1,$var2) = split(/\(\d\d\d\)\(\d\d\d\)/, $var);
>
> This does not seem to work. What am I missing.
> Thanks in advance.
>
> --
> Ian
>
> ======================================================================
> Ian Goldstein | E-Mail nnygsi@ny.ubs.com
> Enterprise Systems Management |
> On assignment at Union Bank of Switzerland |
> ======================================================================
Try this one
$var=123456;
$var =~ /(\d{2})(\d{2})(\d{2})/;
($var1,$var2,$var3) = ($1,$2,$3);
/Michael
------------------------------
Date: Wed, 26 Nov 1997 18:46:23 -0600
From: Kermit Tensmeyer <kermit@ticnet.com>
To: lvirden@cas.org
Subject: Re: perl development package ?
Message-Id: <347CC2DF.87B78646@ticnet.com>
lvirden@cas.org wrote:
>
> According to Kermit Tensmeyer <kermit@ticnet.com>:
> : Sorry, but this type of functionality already exists in the
> : One-True Editor. I can have it track function definition
> : module usage and some pretty good syntax verification.
>
> That's probably true. However, not everyone can/will run TOTE
> (The One True Editor) and so in the spirit of perl doing things
> in multiple ways, some of us were seeking another way.
One _must_ revere the TOTE by using the 'proper' name...
many of the modules that you ask for have already been written
to facilitate development of Perl. (No Perl was not written
using vi.) I learned how to use TOTE (as Epoch) just so I work
on porting Perl 4 to NT...
gotta love those object method browsers... ;-)
>
> : oh by the way... go to a prompt and type perl -dw filename.pl
> :
> : and use the T, W or V commands to examine variables in packages
>
> Okay, I did. I got an error from perl 5.004_054 saying that there
> wasn't any such method as W.
perl -(arguments) filename.pl is the standard method to execute
perl programs.
the parameter -d brings up a shell-level debugger
the parameter -w turns on a lot of pre-run error checking.
>
> : as well. This is documented in the perl man pages AND the camel
>
> Yes, there is some doc on the debugger. I myself would never have
> thought of looking at a debugger for a source code browser.
The debugger is an excellent tool to understand why a particular piece
of code works the way that it does and what ancillary functions support
the target code.
and using vi, and unix shell, a tool such as _cflow_ provides a
method to
track where the code may get executed.
> And
> in fact, looking at the T and V options and trying them still leaves
> me wishing for something like cscope for perl. But my
> plate of tasks is rather full so I just will dream of the day that
> someone out there will get inspired to write a different development
> environment for folk who want to do things differently.
Using V allows one to see the contents of complex data structures
after they are built. T allows one to see the calling sequence.
as I understand the basic request, any development package works with
both the user shell (Win32, Unix) and the programming languages.
Generalized tools beyond those provided might be difficult.
has anybody got _cflow_ to work on NT's command window? has anybody
tried to get it work in an environment where edlin is the editor of
choice?
--
-------
Kermit Tensmeyer (E & T - Networking)
Kermit@ticnet.com Dallas
------------------------------
Date: Wed, 26 Nov 1997 14:16:37 -0800
From: Steven May <stevenjm@olywa.net>
Subject: Re: PERL Hourly Rates
Message-Id: <347C9FC5.9BB8408@olywa.net>
I R A Aggie wrote:
> In article <347C5E08.2FD1E9A@olywa.net>, Steven May
> <stevenjm@olywa.net> wrote:
>
> + Stupidity and laziness and
>
> I thought laziness was a virtue?
'Tis, if it means you're figuring for a better way to do something.
'Tisn't when you want someone else to do something because you won't
exert yourself....
(Especially when you plan to make a profit on it, my pet peeve).
Steve
--
Blackwater-Pacific Services
------------------------------
Date: Wed, 26 Nov 1997 17:13:54 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: PERL Hourly Rates
Message-Id: <65i6i2$gsp@bgtnsc03.worldnet.att.net>
In article <EK9Izo.D7v@ig.co.uk>, Jacqui Caren <Jacqui.Caren@ig.co.uk> wrote:
> Can we agree to differ - I agree with your definition of CGI work
> but my customers use a different definition - and the customer
> is always right :-)
well, when it comes to the client all sorts of things have different
meaning. however, i was more concerned that the original poster was
going to get stung by paying a lot of money to a contracted "CGI
Programmer", rather than "Programmer who can do CGI". i've seen lots
and lots of clients get burned this way, and make most of my money
repairing such situations.
although i have no opinion on this yet, several people (mostly clients
and head-hunter types) have asked when programmers are going to form
a union and demand certification tests. they want some sort of
organization to vouch for programmers and accept responsibility for
unacceptable work.
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Wed, 26 Nov 1997 17:02:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: PERL Hourly Rates
Message-Id: <65i5th$dbd@bgtnsc03.worldnet.att.net>
In article <MPG.ee5fead4fd4c31798969b@news.concentric.net>, jdf@pobox.com
(Jonathan Feinberg) wrote:
> comdog@computerdog.com said...
> > (Jonathan Feinberg) wrote:
>
> > > comdog@computerdog.com said...
>
> > > > CGI scripting is trivial.
> > please keep personal attacks in private mail. if you would like to submit
> > a bug report, you'll have to be more specific since i deal with many
> > web sites.
>
> If you troll, you've got to expect some kind of response.
i was hardly trolling, and expected no where near the zealous response
that statement generated. but i re-iterate - personal messages to me
should go to email, and email only.
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Wed, 26 Nov 1997 13:06:52 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl/UNIX question
Message-Id: <c0sh56.dr1.ln@localhost>
Angelo Kontarinis (akontari@ix.netcom.com) wrote:
: Hi..I am new to CGI/PERL and UNIX. I am installing a WWWboard script on
: a server and I am supposed to chmod a directory. I have no problem
: chmoding a file, but how doe you go about chmoding a directory? Thanks
: so much in advance.
The same way you chmod() a file (though probably with different permissions).
You didn't even try it before posting, did you?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 26 Nov 1997 16:54:18 -0500
From: shawnw@bigwpi.WPI.EDU (Shawn Wagner)
Subject: Re: readdir() and Win32 Perl
Message-Id: <65i5qa$8f1$1@bigwpi.WPI.EDU>
In article <347C8854.F28B8E03@cyber-wizard.com>,
Scott McGee <ScottMcGee@cyber-wizard.com> wrote:
>Hi all,
>
>I have looked in the FAQ's and checked over the messages here, and
>don't see an answer to a problem I am having.
>
>opendir(DIR, "$dirpath\\$dirname") || print "Cannot open $dirname\n";
You don't need the \\, just a /
>@files = grep(!/^\.\.?$/, readdir(DIR));
>closedir(DIR);
>
>while (<@files>) {
> print "$_ \n";
>}
Change the above loop to
for (@files) {
print $_, "\n";
}
Read the camel sections on the angle operator to find
out why.
--
Shawn Wagner - shawnw@wpi.edu
http://mycroft.res.wpi.net/shawnw/
What are we going to do tonight, Brain?
------------------------------
Date: 26 Nov 1997 14:21:47 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: regexp problem
Message-Id: <65i0cr$e9@shoga.wwa.com>
comdog@computerdog.com writes:
>if you only want to change the HREF value, try isolating it from the
>other parts by checking for the value delimiters ['"\s]
>
> #!/usr/bin/perl -w
>
> my @tests;
>
> push @tests, q|<a href="http://www.asd.com" target="top">|;
> push @tests, q|<a target="out" href="http://www.asd.com">|;
>
> foreach ( @tests )
> {
> m/(<a.*?href=['"]) #all the beginning stuff
> (.*?) #the URL portion
> (['"\s].*?>) #whatever is left
> /six;
>
> print "$1\n$2\n$3\n\n";
> }
I'd be more anal than this... Especially since it can be accomplished
very easily by stealing code written by Gisle Aas -- it would go
somewhat like this:
m/(<\s* a \b [^>]+ \b href \s* = \s* (["']?)) ([^>\s]+) (\2 [^>]* >)/ix;
Except now the relevant parts are $1, $3 and $4...
/a.*?href/ is too fragile a pattern for the A tag, especially
after the rumours of Netscape's introducing the attachref tag...
------------------------------
Date: Thu, 27 Nov 1997 02:56:36 +0000
From: Mark Worsdall <jaydee@worsdall.demon.co.uk>
Subject: Re: Removing Files older than 14 days
Message-Id: <wYxhmEAkFOf0EwW1@worsdall.demon.co.uk>
In article <880492908.29258.0.nnrp-02.c2de48f0@news.demon.co.uk>, Hugh
<hnews@harvest-lodge.demon.co.uk> writes
>I am having difficulty writing an efficient script to delete all files in a
>preset directory over a certain age. If a file is older than 14 days I want
>to delete it. There are likely to be upwards of a couple of thousand or so
>files in the directory. How is the best way to check the create dates and
>delete if appropriate. As I said there is no need to recurse subdirs as they
>won't exist. All files to be deleted will have a .ABC suffix, the routine
>should ignore files without this.
>
#!/usr/local/bin/perl
# webmaster@shadow.org.uk
#
# This is the location of your homepages on the server
$startloc = '/foo/bar/directory';
# This is the number of days ago to check for.
# i.e. any file updated 2 days since NOW
# would be:- $numdaysAgo = '2';
$numdaysAgo = '14';
use Cwd;
use File::Find;
find (\&tell_time, $startloc); # Call tell_time for every file under
# current directory
sub tell_time {
return if (-d $_); # Not if it is a directory
return if (-l $_); # Not if it is a symbolic link
return if (-z $_); # Not if it is a zero length file
# if last modified date greater than our days
return if ((-M $_) > $numdaysAgo );
# The lines below will display in fractions of days how old the file is
print "$File::Find::Dir/$_ ==> ", (-M $_), "\n";
# Get the location of this current file
$fullpath = Cwd::getcwd;
# Now append filename to path to give us full filepath
$fullpath = $fullpath . '/' . $_;
# This is the command that will delete the file.
system("OS specifc delete command", $fullpath);
}
--
Mark Worsdall - Oh no, I've run out of underpants :(
Home:- jaydeeATworsdall.demon.co.uk WEB site:- http://www.worsdall.demon.co.uk
Shadow:- webmasterATshadow.org.uk WEB site:- http://www.shadow.org.uk
------------------------------
Date: Thu, 27 Nov 1997 20:15:02 GMT
From: jelly&ham_abuse@omen.net.au (Hel's Synic)
Subject: script refuses to print variables to file but happily does to screen
Message-Id: <65is65$l6v$1@demeter.omen.com.au>
AArrrgh! My script refuses to print variables to file but happily does
to screen.. I've tried all sorts of permutations and combinations of
getting this happening, but, it just refuses to go. Very frustrating.
I'm hoping that there's something utterly stupidly simple that I'm
overlooking.
The aim of the script is to deweb POST data and then print it first to
screen (debugging, really) and then to a file.
Sample output is at villain.omen.net.au/~synic/scripts/test.html.
Below is the script code:
--------
#!/usr/bin/perl
#
#Test thing.
#
#open file first up.
#Below, this configs the browser to receive html
print "Content-type: text/html\n\n";
#This is good for blocks of standard html
print <<Label1;
<html>
<title>Peter's File-writing test</title>
<center>
<h1>This is a file-writing test!</h1>
</center>
Label1
#This is an output of the raw stuff from a webpage form.
#The $buffer could be called -anything-, but, the capitalised
#stuff is pretty mandatory.
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<([^>]|\n)*>//g;
$value =~ s/<//g;
$value =~ s/>//g;
$FORM{$name} = $value;
}
#hopefully, now, the various variables have been initialised. now to
test
#it by outputting them.
$embobbo = "embobbo flavoured chips";
print "Embobbo is: ", $embobbo;
$bobbo = $FORM{'location'};
print "location,Bobbo is: ", $bobbo;
$book = $FORM{'something'};
print "something,Book is: ", $book;
print "These are the outputted variables that will later be ";
print "sent to the file.<ul>";
print " \n";
print "<li>Something: ", $FORM{'something'};
print " \n";
print "<li>Location: ", $FORM{'location'};
print " \n";
print "<li>recipient: ", $FORM{'recipient'};
print " \n";
print "</ul><P>";
print " \n";
$embobbo = "embobbo flavoured chips";
print "Embobbo is: ", $embobbo;
print " \n";
$bobbo = $FORM{'location'};
print "Bobbo (location) is: ", $bobbo;
print " \n";
$book = $FORM{'something'};
print "Book (something) is: ", $book;
print " \n";
print "<hr>Now the File Bit<hr>";
open (SESAME, ">>/home/synic/public_html/scripts/test.html");
# open (SESAME, ">/home/synic/public_html/scripts/test.html");
print SESAME "\n<hr>";
print SESAME "TESTING\n";
print SESAME " \n";
print SESAME "Embobbo is: ", $embobbo;
print SESAME " \n";
print SESAME "Bobbo (location) is:";
print SESAME "$bobbo";
print SESAME " \n";
print SESAME "This is the final bit with the vars there ";
print SESAME "for us to use them.\n";
print SESAME "something:";
print SESAME $FORM{'something'};
print SESAME " \n";
print SESAME "location:", $FORM{'location'};
print SESAME " \n";
print SESAME "recipient: ";
print SESAME $FORM{'recipient'};
print SESAME "\n";
select(SESAME);
print "<hr>";
print " \n";
print "This is the final bit where the variables -ought- to be
waiting: ";
print "\n<ul>";
print " \n";
print "<li>Something: ", $FORM{'something'};
print " \n";
print "<li>Location: ", $FORM{'location'};
print " \n";
print "<li>recipient: ", $FORM{'recipient'};
print " \n";
print "</ul><P>";
print " \n";
$embobbo = "embobbo flavoured chips";
print "Embobbo is: ", $embobbo;
print " \n";
$bobbo = $FORM{'location'};
print "location,Bobbo is: ", $bobbo;
print " \n";
$book = $FORM{'something'};
print "something,Book is: ", $book;
print "\n<hr>";
close(SESAME);
select(STDOUT);
print "\n";
print "Well, the output ought to be <a
href=\"http://villain.omen.net.au/~synic/scripts/test.html\">here</A>";
print "\n";
#Finish up.
exit;
--------
--
-- .-. . -+- .-. .-,.-, --- : -------------------------
|_;.-. +- .-. .-. | | .-. | | * .-. _oo__ www.omen.com.au/~synic
| |-' | |-' | | | .-| +- +- | | | //`'\_ synic@omen.com.au
-- ' `-' `-'`-' ' '' `-'`-" | | ' ' ' -- \ --------------------------
------------------------------
Date: Wed, 26 Nov 1997 13:32:23 -0800
From: "Tim Gilman" <tdgilman@DELETETHISbest.com>
Subject: Re: Strange 'print Location:' problem with Perl
Message-Id: <65i4g4$h3q$1@nntp2.ba.best.com>
Andre L. wrote in message ...
>
>Hm. Not an expert, but... I think it is a string concatenation syntax
>error (look out for the dots -- and also the parentheses are missing):
>
>print("Location: ".$article."\n\n");
thanks for the reply. Actually, this wasn't the problem. I tried your
suggestion and got the same behavior. One thing I have found out is that
this problem only happened for me using IE4.0. Netscape 4 worked fine.
------------------------------
Date: Wed, 26 Nov 1997 13:51:09 -0800
From: "Tim Gilman" <tdgilman@DELETETHISbest.com>
Subject: Re: Strange 'print Location:' problem with Perl
Message-Id: <65i5jc$hkl$1@nntp2.ba.best.com>
Gary Weinstein wrote in message <65hnd8$obi$1@news.depaul.edu>...
>
>Since there is no path information in the URL, the web browser will request
>it from the *same* directory as the program that referenced it, which in
>this case is a CGI program and (probably) resides under /cgi-bin. This
means
>it will request /cgi-bin/sib97181.pdf. I doubt this is the correct location
>(at least it shouldn't be since a PDF file is definitely not executable).
>
>Try something like this instead:
>
> print "Location: /articles/$article\n\n"
My CGI script is in the same directory as the pdf file and referring
document. But actually, I've tried that suggestion already. Using a full
path has exactly the same problem.
What I found out is that this problem only seems to exist with IE4.0. It
works fine in Netscape 4. I also found an alternate way of launching a new
location on http://www.comv.com/redir.html. The page has an edit box where
you can type in a URL and press "Take Me There!" If you type in a URL that
points to an HTML page, it works fine. But (in IE4.0) if you type in a pdf
file (for example, http://www.structint.com/tech/sib97181.pdf) then it shows
a blank page! However, if I open the pdf url using File|Open, then it works
fine!
I don't get it. Like I said before, if I hard code in the filename, like:
print "Location: sib97181.pdf\n\n";
Then it works fine. But when the filename is a string coming from a form,
then it will NOT work in IE4.0. Again, this problem only exists with PDF
files. If the string is an HTML file, then it works fine. Too weird....
--
Tim Gilman (please remove DELETETHIS from the address when replying)
http://www.best.com/~tdgilman
------------------------------
Date: Wed, 26 Nov 1997 08:40:08 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/[A-Z]//d>
Subject: Re: strange problem with regular expression memory variables
Message-Id: <65hjid$nnh@news.microsoft.com>
John Rodkey wrote in message ...
>I'm new to perl, so beat me softly, OK?
Welcome! We were all new once . . .
>Yes, I've looked at the man pages (perlre, perlop)
>and the FAQ. But no reference to ...
>
>Regular expression matching from variables and
>referencing RE memory variables indirectly. to wit:
>
>I have need to store a regular expression in a variable,
>and then assign another variable the memory variable
>which must be determined based on yet another variable.
Marvelously incomprehensible. Have you considered a career in foreign
service? (Just kidding)
>Here's the code I'm attempting...
>
>#!/usr/local/bin/perl -w
># match one or more digits surrounded by non-digits
>$RE = "m@\\D+(\\d+).*@" ;
>$_ = "Our 923 number in the middle of a String";
>$N = '$1';
>
>if ( $_=~$RE ) {
> $result=$$N ;
>} else {
> $result=0;
>}
>print "$_\n";
>print "$RE\n";
>print "$$N\n";
>print "$result\n";
>0;
>
>When I run it, I always get 0 as the result, and it
>says access to $$N is to an uninitialized value.
>
>What am I missing here?
I think the problem here is that you're putting the delimiters into the
variable. Since you're searching for digits I don't see any reason why you
wouldn't be able to use a normal // syntax to match something, so you might
get better results with this:
$RE = "\\D+(\\d+).*";
if ($_ =~ /$RE/) { . . . }
Or, since $_ is the default for the match operation, you can shorten this a
bit more by changing the second line to
if (/$RE/) { . . . }
If you're going to delve much farther into Perl you'll probably want to pick
up O'Reilly's "Mastering Regular Expressions" by Jeffrey Friedl. It has an
entire chapter devoted to regular expressions in Perl.
Hope this helps,
-- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl
------------------------------
Date: Wed, 26 Nov 1997 17:26:56 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: sytem command test
Message-Id: <65i7af$gsp@bgtnsc03.worldnet.att.net>
In article <347C485C.658B@swansea.ac.uk>, eeparrad@swansea.ac.uk wrote:
> I want to test out perl's system() command. I have been told to use
> something along the lines of "pwd >/tmp/pwd" so that I can actualy read
> the file in tmp. Can anyone tell we the correct way to implement this?
you can do something like:
$status = system '/bin/pwd', '> /tmp/pwd';
see the perlfunc man page for more details.
good luck :)
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Wed, 26 Nov 1997 15:37:57 -0700
From: Bill Eberle <wile@inficad.com>
Subject: truncating a string
Message-Id: <65i7t1$8c0$1@news.inficad.com>
I have a problem with limiting the size of a string variable. I want to
take the first ten characters and delete the rest. Does anyone know an
easy way to do this, short of reading the first ten characters into an
array? Thanks.
Please remove <nospam> from my address if responding via email.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1379
**************************************