[22054] in Perl-Users-Digest
Perl-Users Digest, Issue: 4276 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 17 18:05:38 2002
Date: Tue, 17 Dec 2002 15:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 17 Dec 2002 Volume: 10 Number: 4276
Today's topics:
comparing mangled times perlistically! (qanda)
Re: comparing mangled times perlistically! <goldbb2@earthlink.net>
Re: comparing mangled times perlistically! <krahnj@acm.org>
Re: DBI::mysql Problem on Linux <jeff@jeffs-place.org>
Extracting Strings Matching a Regular Expression <hal@thresholddigital.com>
Re: Extracting Strings Matching a Regular Expression <usenet@dwall.fastmail.fm>
Re: Extracting Strings Matching a Regular Expression <perl-dvd@darklaser.com>
Re: Extracting Strings Matching a Regular Expression (Tad McClellan)
Re: Extracting Strings Matching a Regular Expression (Malcolm Dew-Jones)
Re: Extracting Strings Matching a Regular Expression <hal@thresholddigital.com>
Re: Extracting Strings Matching a Regular Expression (Tad McClellan)
ExtUtils::MakeMaker: installing scripts to sbin? (Paul Cody Johnston)
Re: FTPing without Net::FTP (Tad McClellan)
Re: images presented on web through perlscript <perl-dvd@darklaser.com>
Re: Is it possible to change windows background via Per <goldbb2@earthlink.net>
Re: Is it safe to return a reference to local or lexica <mgjv@tradingpost.com.au>
Re: members area in perl ??? <mgjv@tradingpost.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Dec 2002 13:25:44 -0800
From: fumail@freeuk.com (qanda)
Subject: comparing mangled times perlistically!
Message-Id: <62b4710f.0212171325.674d7f24@posting.google.com>
Hi all, here's a routine to compare fixed format date and times, any
help greatly appreciated, I'm sure this can be done a lot easier than
here ...
thanks.
#!/usr/bin/perl
use strict;
use warnings;
comp_times();
sub comp_times {
my $drift = 30; # Times are equal if within $drift seconds.
my @f1_times = ();
my @f2_times = ();
my $f1i = 0;
my $f2i = 0;
my $len = 13;
while( <DATA> ) {
my @flds = split( /,/, $_, -1 );
# Remove microseconds and 'T' separator.
$flds[2] =~ s/\.\d+$|T//g;
# Simulate 2 files using field1 of __DATA__ lines.
if( $flds[0] eq "file1" ) {
$f1_times[$f1i] = $flds[2];
$f1_times[$f1i++] .= 0 x (14 - length($flds[2]) );
}
else {
$f2_times[$f2i] = $flds[2];
$f2_times[$f2i++] .= 0 x (14 - length($flds[2]) );
}
}
for( my $i=0; $i < @f1_times; $i++ ) {
use Time::Local;
# print "$f1_times[$i] - $f2_times[$i]\n";
my $f1_time = scalar(timelocal(
substr( $f1_times[$i], 12,2 ),
substr( $f1_times[$i], 10,2 ),
substr( $f1_times[$i], 8,2 ),
substr( $f1_times[$i], 6,2 ),
substr( $f1_times[$i], 4,2 ),
substr( $f1_times[$i], 2,2 ) ));
my $f2_time = scalar(timelocal(
substr( $f2_times[$i], 12,2 ),
substr( $f2_times[$i], 10,2 ),
substr( $f2_times[$i], 8,2 ),
substr( $f2_times[$i], 6,2 ),
substr( $f2_times[$i], 4,2 ),
substr( $f2_times[$i], 2,2 ) ));
my $diff = abs($f1_time - $f2_time);
if( $diff <= $drift ) {
print "Matched\n";
}
else {
print "Not matched\n";
}
}
}
# Date/time fields
# YYYYMMDDTHHMMSS.IIIIII
# We assume dates will not be prior to 1970.
# T is delimter between date and time.
# 00 in any time sub-field (HH,MM,SS) makes time field truncate.
# eg 20011201T121300 truncates to 20011201T1213
# If time is midnight (000000) T is dropped and whole time field
truncated.
#
__DATA__
file1,f2,20020901T235950,f4
file1,f2,20020902T102030.123,f4
file1,f2,20020903T102535,f4
file1,f2,20020904T103535.456,f4
file2,f2,20021001,f4
file2,f2,20020902T102045,f4
file2,f2,20020903T102030,f4
file2,f2,20020904T103537,f4
------------------------------
Date: Tue, 17 Dec 2002 17:17:28 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: comparing mangled times perlistically!
Message-Id: <3DFFA278.17ADC893@earthlink.net>
qanda wrote:
qanda wrote:
[snip]
> # Date/time fields
> # YYYYMMDDTHHMMSS.IIIIII
> # We assume dates will not be prior to 1970.
Why? The timelocal() function can parse such dates, I think.
> # T is delimter between date and time.
If the date is a fixed length string, then why is this needed?
> # 00 in any time sub-field (HH,MM,SS) makes time field truncate.
If HH is 00, but MM and SS are not, does it all get truncated? I hope
not.
> # eg 20011201T121300 truncates to 20011201T1213
> # If time is midnight (000000) T is dropped and whole time field
> # truncated.
> #
> __DATA__
> file1,f2,20020901T235950,f4
> file1,f2,20020902T102030.123,f4
> file1,f2,20020903T102535,f4
> file1,f2,20020904T103535.456,f4
> file2,f2,20021001,f4
> file2,f2,20020902T102045,f4
> file2,f2,20020903T102030,f4
> file2,f2,20020904T103537,f4
[snip]
I would suggest something like the following:
my %data;
while( <DATA> ) {
my ($file, undef, $datetime) = split /,/;
$datetime .= "0" . (14 - length $datetime);
push @{ $data{$file} } => $datetime;
}
my @files = keys %data;
my @times = values %data;
# If file1 has 4 samples, and file2 has 5 samples,
# then clearly something is wrong.
unless( 1 == keys %{{ map {;0+@$_,1} @times }} ) {
die "All files must have the same number of time samples!\n";
}
for my $i ( 0 .. $#{ $times[0] } ) {
# Convert the data using unpack() and timelocal().
my @t = map {
defined($_) or $_ = 0 for # turn undef values to 0s.
# YYYYMMDDTHHMMSS.IIIIII
my ($YYYY, $MM, $DD, $hh, $mm, $ss, $us) =
unpack( 'A4 A2 A2 x A2 A2 A2 x A4', $_->[$i] );
timelocal( $ss, $mm, $hh, $DD, $MM, $YYYY ) +
($us / 1_000_000);
} @times;
my $failed = 0;
for my $j ( 0 .. $#t-1 ) { for my $k ( 1 .. $#t ) {
next if $j == $k or abs( $t[$j] - $t[$k] ) <= $diff;
print "In files $files[$j] and $files[$k], sample # $i".
" differs: $t[$j] != $t[$k]\n";
$failed = 1;
} }
print "Sample $i matches across all files [@files]\n"
unless $failed;
}
__END__
[untested]
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 17 Dec 2002 22:55:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: comparing mangled times perlistically!
Message-Id: <3DFFAB29.533F6B09@acm.org>
qanda wrote:
>
> Hi all, here's a routine to compare fixed format date and times, any
> help greatly appreciated, I'm sure this can be done a lot easier than
> here ...
>
> thanks.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> comp_times();
>
> sub comp_times {
> my $drift = 30; # Times are equal if within $drift seconds.
> my @f1_times = ();
> my @f2_times = ();
> my $f1i = 0;
> my $f2i = 0;
> my $len = 13;
>
> while( <DATA> ) {
> my @flds = split( /,/, $_, -1 );
^^^^^^^^
Where do people learn this stuff? :-)
> # Remove microseconds and 'T' separator.
> $flds[2] =~ s/\.\d+$|T//g;
>
> # Simulate 2 files using field1 of __DATA__ lines.
>
> if( $flds[0] eq "file1" ) {
> $f1_times[$f1i] = $flds[2];
> $f1_times[$f1i++] .= 0 x (14 - length($flds[2]) );
> }
> else {
> $f2_times[$f2i] = $flds[2];
> $f2_times[$f2i++] .= 0 x (14 - length($flds[2]) );
> }
> }
>
> for( my $i=0; $i < @f1_times; $i++ ) {
> use Time::Local;
> # print "$f1_times[$i] - $f2_times[$i]\n";
>
> my $f1_time = scalar(timelocal(
> substr( $f1_times[$i], 12,2 ),
> substr( $f1_times[$i], 10,2 ),
> substr( $f1_times[$i], 8,2 ),
> substr( $f1_times[$i], 6,2 ),
> substr( $f1_times[$i], 4,2 ),
You have an error here.
> substr( $f1_times[$i], 2,2 ) ));
And a potental error here
> my $f2_time = scalar(timelocal(
> substr( $f2_times[$i], 12,2 ),
> substr( $f2_times[$i], 10,2 ),
> substr( $f2_times[$i], 8,2 ),
> substr( $f2_times[$i], 6,2 ),
> substr( $f2_times[$i], 4,2 ),
Same error here. You are passing the human readable month number (1-12)
to timelocal but it is expecting a range of 0-11.
> substr( $f2_times[$i], 2,2 ) ));
You are passing the last two digits of the year to localtime. This
_should_ work (it does on my computer) but it might fail for some dates.
> my $diff = abs($f1_time - $f2_time);
> if( $diff <= $drift ) {
> print "Matched\n";
> }
> else {
> print "Not matched\n";
> }
> }
> }
>
> # Date/time fields
> # YYYYMMDDTHHMMSS.IIIIII
> # We assume dates will not be prior to 1970.
> # T is delimter between date and time.
> # 00 in any time sub-field (HH,MM,SS) makes time field truncate.
> # eg 20011201T121300 truncates to 20011201T1213
> # If time is midnight (000000) T is dropped and whole time field
> truncated.
> #
> __DATA__
> file1,f2,20020901T235950,f4
> file1,f2,20020902T102030.123,f4
> file1,f2,20020903T102535,f4
> file1,f2,20020904T103535.456,f4
> file2,f2,20021001,f4
> file2,f2,20020902T102045,f4
> file2,f2,20020903T102030,f4
> file2,f2,20020904T103537,f4
I would probably write it like this:
sub comp_times {
use Time::Local;
my $drift = 30; # Times are equal if within $drift seconds.
my @f1_times;
my @f2_times;
while ( <DATA> ) {
my @flds = split /,/;
# Remove microseconds and 'T' separator.
$flds[2] =~ s/\.\d+$|T//g;
my @date = reverse unpack 'a4 a2 a2 a2 a2 a2', $flds[2];
$date[5] -= 1900;
$date[4] -= 1;
# Simulate 2 files using field1 of __DATA__ lines.
push @{ $flds[0] eq 'file1' ? \@f1_times : \@f2_times }, \@date;
}
for( my $i = 0; $i < @f1_times; ++$i ) {
my $f1_time = timelocal( @{$f1_times[$i]} );
my $f2_time = timelocal( @{$f2_times[$i]} );
my $diff = abs( $f1_time - $f2_time );
if( $diff <= $drift ) {
print "Matched\n";
}
else {
print "Not matched\n";
}
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 17 Dec 2002 20:02:53 GMT
From: "Jeff Walter" <jeff@jeffs-place.org>
Subject: Re: DBI::mysql Problem on Linux
Message-Id: <NpLL9.380201$WL3.114839@rwcrnsc54>
> ...anyway, the error you are getting is from MySQL, it means you are
> using the wrong password (or perhaps never set one up, or perhaps
> haven't GRANTed rights to the user you are logging in as?)
Well, I was quite certain it was a problem with DBI, but it seems the
problem was with Config::Tiny. I stuck a print statement containing all the
info passes on to DBI...It failed with uninitialized values... So the
bitter truth is that Config::Tiny is the issue. Are there any other good
cross-platform config loading modules out there?
Thanks!
Jeff Walter
jeff@jeffs-place.org
------------------------------
Date: Tue, 17 Dec 2002 19:12:35 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Extracting Strings Matching a Regular Expression
Message-Id: <DGKL9.391336$NH2.29368@sccrnsc01>
If I have a line of text that includes a zip+4 sort (American postal codes,
5 digits, a dash, and 4 more digits), I know I can check to see if that
line contains a zip+4 with this:
if ($line =~ /[0-9]{5}-[0-9]{4}/ {do zip+4 stuff}
But is there any way, using a regex or search and replace that I can extract
that zip+4 from the line of text? For example, I tried:
$line =~ s/^.*[0-9]{5}-[0-9]{4}.*$/[0-9]{5}-[0-9]{4}/g;
but it takes the target string literally. I'd love to find a way to do
something like this:
$zip = $line =~ s/[0-9]{5}-[0-9]{4}/[0-9]{5}-[0-9]{4}/g;
(I know this won't work as written) and have $zip the contain the zip+4
numbers. Is there any way to do this? Or to do something close, like this:
$line =~ s/[0-9]{5}-[0-9]{4}/[0-9]{5}-[0-9]{4}/g;
(Again, I know this won't work as written) and have $line contain the zip+4
code I'm looking for?
This would be a BIG help to me -- not just for zip codes, but for extracting
a LOT of different text from capture files containing tons of formatting
codes and such.
Thanks!
Hal
------------------------------
Date: Tue, 17 Dec 2002 19:26:31 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <Xns92E792E90CB27dkwwashere@216.168.3.30>
Hal Vaughan <hal@thresholddigital.com> wrote on 17 Dec 2002:
> If I have a line of text that includes a zip+4 sort (American
> postal codes, 5 digits, a dash, and 4 more digits), I know I can
> check to see if that line contains a zip+4 with this:
>
> if ($line =~ /[0-9]{5}-[0-9]{4}/ {do zip+4 stuff}
>
> But is there any way, using a regex or search and replace that I
> can extract that zip+4 from the line of text?
Use capturing parentheses:
print $1 if $line =~ /(\d{5}-\d{4})/;
or some variation on that. If there are multiple zip codes in a
line, something like this will work:
my $text = 'blah 54589-3267 blah blah 23432-3433 blah blah';
while ( $text =~ /(\d{5}-\d{4})/g ) {
print "$1\n";
}
By the way, I used \d instead of [0-9] so I wouldn't have to type as
much.
See perlrequick and perlre for more information.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 17 Dec 2002 12:30:24 -0700
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <6QKL9.18398$K5.4674@fe01>
Again someone beat me to it, but this still has lots of good info for
you.
"Hal Vaughan" <hal@thresholddigital.com> wrote in message
news:DGKL9.391336$NH2.29368@sccrnsc01...
> If I have a line of text that includes a zip+4 sort (American postal
codes,
> 5 digits, a dash, and 4 more digits), I know I can check to see if
that
> line contains a zip+4 with this:
>
> if ($line =~ /[0-9]{5}-[0-9]{4}/ {do zip+4 stuff}
>
> But is there any way, using a regex or search and replace that I can
extract
> that zip+4 from the line of text? For example, I tried:
>
> $line =~ s/^.*[0-9]{5}-[0-9]{4}.*$/[0-9]{5}-[0-9]{4}/g;
Thats because the second half of the search and replace of the regex is
a string not an expression.
You can do this thought
$line =~ /(\d{5})-(\d{4}))/;
# now the special var $1 contains the 5 digit part
# and the special var $2 contains the 4 digit part
Note that \d is the same as [0-9]
another way of doing it would be
my ($fivedig, $fourdig) = $line =~ /(\d{5})-(\d{4}))/;
or just to get the 4 digit:
my $fourdig = $line =~ /\d{5}-(\d{4}))/
if you will notice, I put parens arround the part I want to capture.
>
> but it takes the target string literally. I'd love to find a way to
do
> something like this:
>
> $zip = $line =~ s/[0-9]{5}-[0-9]{4}/[0-9]{5}-[0-9]{4}/g;
>
> (I know this won't work as written) and have $zip the contain the
zip+4
> numbers. Is there any way to do this? Or to do something close, like
this:
>
> $line =~ s/[0-9]{5}-[0-9]{4}/[0-9]{5}-[0-9]{4}/g;
>
> (Again, I know this won't work as written) and have $line contain the
zip+4
> code I'm looking for?
>
> This would be a BIG help to me -- not just for zip codes, but for
extracting
> a LOT of different text from capture files containing tons of
formatting
> codes and such.
>
>
> Thanks!
Your welcome
>
> Hal
Regards,
David
------------------------------
Date: Tue, 17 Dec 2002 13:24:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <slrnavuuer.1ri.tadmc@magna.augustmail.com>
Hal Vaughan <hal@thresholddigital.com> wrote:
> If I have a line of text that includes a zip+4 sort (American postal codes,
> 5 digits, a dash, and 4 more digits), I know I can check to see if that
> line contains a zip+4 with this:
>
> if ($line =~ /[0-9]{5}-[0-9]{4}/ {do zip+4 stuff}
> But is there any way, using a regex or search and replace that I can extract
> that zip+4 from the line of text?
my $zip = $1 if $line =~ /([0-9]{5}-[0-9]{4})/;
or
my $zip = $1 if $line =~ /(\d{5}-\d{4})/;
> For example, I tried:
> $line =~ s/^.*[0-9]{5}-[0-9]{4}.*$/[0-9]{5}-[0-9]{4}/g;
>
> but it takes the target string literally.
^^^^^^
Of course, because it is a string, not a regex.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Dec 2002 11:34:10 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <3dff7c32@news.victoria.tc.ca>
Hal Vaughan (hal@thresholddigital.com) wrote:
: If I have a line of text that includes a zip+4 sort (American postal codes,
: 5 digits, a dash, and 4 more digits), I know I can check to see if that
: line contains a zip+4 with this:
: if ($line =~ /[0-9]{5}-[0-9]{4}/ {do zip+4 stuff}
: But is there any way, using a regex or search and replace that I can extract
: that zip+4 from the line of text? For example, I tried:
Yes, you put *capturing* brackets around the part(s) you want to
*capture*.
I'm sure that `perldoc perlre' will explain this in detail, and if it
seems too deep too quickly then read any of numerous introductions about
regular expressions (key word here is "capturing", and $1, $2, $3 etc...)
The results can be returned in variables like $1 $2 or copied into a list
Simple examples
$line =~ m/(\d+)/; # capture a run of one or more digits
# => $1 now has the first set of digits from the line
same as above, but put the captured substring into your own variable.
my $x;
($x) = $line =~ m/(\d+)/; # $x gets what $1 got above
# note the ()'s around $x !
This also works in the s/// command, one trivial example
my $line = "The number is 100.";
$line =~ s/(\d+)/bigger than $1 but not so pretty/;
print $line;
------------------------------
Date: Tue, 17 Dec 2002 20:15:31 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <DBLL9.394729$QZ.63652@sccrnsc02>
Thanks to all who responded. I found out earlier today that when I upgraded
my system (Mandrake 8.2 => 9.0, RPM upgrade only), it somehow broke
perldoc. I had gone through both the Blue Camel and Blue Llama, but had
trouble finding what I wanted. It seems like no matter how closely I look
at something in Perl, there's a better or different answer just around the
corner.
Using the parenthesis works perfectly. It also saves me between 5-10 lines
of code in a routine that is looped through quite frequently.
Thanks again!
Hal
------------------------------
Date: Tue, 17 Dec 2002 15:12:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <slrnavv4ql.25a.tadmc@magna.augustmail.com>
David <perl-dvd@darklaser.com> wrote:
> You can do this thought
You can, but you shouldn't.
> $line =~ /(\d{5})-(\d{4}))/;
> # now the special var $1 contains the 5 digit part
> # and the special var $2 contains the 4 digit part
They might contain that, they might not.
The capture variable's values are only updated for a _successful_ match,
so you should make sure that the match succeeded before using them:
if ( $line =~ /(\d{5})-(\d{4}))/ ) {
# now the special var $1 contains the 5 digit part
# and the special var $2 contains the 4 digit part
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Dec 2002 13:37:26 -0800
From: pcj-google@inxar.org (Paul Cody Johnston)
Subject: ExtUtils::MakeMaker: installing scripts to sbin?
Message-Id: <9d4ea49.0212171337.556f7028@posting.google.com>
I have a utility that would belong better in /usr/sbin rather than
/usr/bin. Using MakeMaker, how do I specify that? Currently the only
way I understand how to do that is to tell the user installing the
script to run:
$ perl Makefile.PL INSTALLSCRIPT=/usr/sbin
But of course that puts the onus on the user to put things in the
right place. Does there not exist the notion of a system binary
directory in MakeMaker?
Thanks,
Paul
------------------------------
Date: Tue, 17 Dec 2002 13:26:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FTPing without Net::FTP
Message-Id: <slrnavuujc.1ri.tadmc@magna.augustmail.com>
Cold Cathoid <mememe@meme.com> wrote:
> I did some research and the Net::FTP would be really
> handy. Unfortunently it's not installed on the box I am using. I talked to
> our sysadmin and he said he could install it ... one day ... he figures in a
> couple months he could get around to it. It's not high on his list of
> priorities.
You don't need the sysadmin. Install it yourself.
perldoc -q module
How do I install a module from CPAN?
How do I keep my own module/library directory?
> Any thoughts?
Check the Perl FAQ before posting to the Perl newsgroup.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 17 Dec 2002 12:21:59 -0700
From: "David" <perl-dvd@darklaser.com>
Subject: Re: images presented on web through perlscript
Message-Id: <eIKL9.18390$K5.1946@fe01>
"stig" <nospam_stigerikson@yahoo.se> wrote in message
news:atnnfe$mv6$1@oden.abc.se...
> hi
>
> on my webserver i have a cgi-bin area, where perlscrips are executed.
> also i have some images there, this images cannot be displayed if
requested
> as http://server.com/cgi-bin/image.png since server will not allow
this.
> this is good.
>
> however i would like to create a script that controls the user and
then
> displays a html-page that displays the image as well.
> would it be possible, or du i have to save the images in an area that
has
> webaccess for everyone?
No, not necissarily. Observe the following code:
-------------------------------------------------
#!/usr/bin/perl
use strict;
print("Content-type: Image/gif\n");
print("Pragma: no-cache\n");
print("Expires: Friday, 01-Aug-80 00:00:00 GMT\n\n");
local $/ = undef; # file slurp mode
open(INFILE, "</path/to/image.gif");
my $img = <INFILE>;
close(INFILE);
binmode STDOUT;
print $img;
exit;
-------------------------------------------------
If you put this in a script all of its own, then you can use it in an
image tag when printing out your html like so:
<img src="http://yourdomain.com/cgi-bin/showimage.pl">
You of course, need to replace /path/to/image.gif with the path to your
image. And if you want to do this well, you aught to use CGI.pm or
something inside your showimage.pl script, then you could use this
script to show any image you want that sits behind the scenes, and your
call could be something like this:
<img src="http://yourdomain.com/cgi-bin/showimage.pl?img=test.gif">
Regards,
David
------------------------------
Date: Tue, 17 Dec 2002 16:20:18 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is it possible to change windows background via Perl?
Message-Id: <3DFF9512.9FE92D6B@earthlink.net>
Jim Agnew wrote:
[snip. The question was: How do I change the desktop image on windows,
using perl]
use Win32::API 2.0;
use constant SystemParametersInfo => Win32::API->new(
qw(user32 SystemParametersInfoA NNPN N)) || die $^E;
use constant SPIF_SETDESKWALLPAPER => 20;
use constant SPIF_UPDATEINIFILE => 1;
SystemParametersInfo->Call(
SPIF_SETDESKWALLPAPER, 0,
$filepath,
SPIF_UPDATEINIFILE) or die $^E;
Where $filepath is an absolute path to a .bmp file.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 17 Dec 2002 22:08:16 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Is it safe to return a reference to local or lexical data?
Message-Id: <slrnavv867.865.mgjv@verbruggen.comdyn.com.au>
On Tue, 17 Dec 2002 09:36:28 -0500,
Christian Caron <nospam@nospam.org> wrote:
>
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnavub72.2nm.tadmc@magna.augustmail.com...
>> Christian Caron <nospam@nospam.org> wrote:
>> >
>> >>
>> >> 3.18: Is it safe to return a reference to local or lexical data?
>>
>>
>> > Is it me or is there a problem with that?
>>
>>
>> Can't tell unless you let us know what you think the problem is.
>>
>>
>
> I thought print "@many\n"; would return numbers:
>
> 1 2 3 4 5 6 7 8 9 10
> 1 2 3 4 5...
let's revisit the code that creates @many:
for $i ( 1 .. 10 ) {
push @many, makeone();
}
where each invocation of makeone() returns a (unique) reference to an
array. push() simply pushes the argument list onto the array. That
means that given that @many is empty to start off with, after this
loop it will have 10 elements, each element being a value returned by
makeone(). Since makeone() returns a reference to an array, there
should be 10 references to arrays, which is exactly what happens.
> Maybe it's my misunderstanding of (Perl | English | FAQ)... I think I now
> know it is indeed returning the right thing (10 references to arrays that
> contain 10 numbers each).
I am not sure why you think there should be numbers. The 1..10 in
there simply serves as a counter for the loop, the values themselves
are never used (the $i loop variable shouldn't really be there, it just
distracts).
Oh, I suddenly see what you mean. The sub makeone() looks like this:
sub makeone {
local @a = ( 1 .. 10 );
return \@a;
}
meaning that each reference points to an array with 10 elements,
valued 1 to 10. Is that what you expect to see?
Well, print, or rather, stringification simply doesn't work that way
in Perl. When a reference gets stringified, it becomes a textual
representation of itself, not of what it refers to. If you want to do
a "deep" stringification, i.e. each reference is followed and what it
refers to is stringified in some way, you could use the Data::Dumper
module, or write something yourself. Data::Dumper would give you
something like (reformatted to fit 80 characters per line):
$VAR1 = [
[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],
[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],
[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10],
[1,2,3,4,5,6,7,8,9,10]];
Is that what you expected?
Martien
--
|
Martien Verbruggen | That's funny, that plane's dustin' crops
Trading Post Australia | where there ain't no crops.
|
------------------------------
Date: Tue, 17 Dec 2002 22:16:51 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: members area in perl ???
Message-Id: <slrnavv8ma.865.mgjv@verbruggen.comdyn.com.au>
On Tue, 17 Dec 2002 16:36:34 GMT,
opt cool dude <control153@NOSPAMyahoo.com> wrote:
> newbee here ....
> i need to create a members area in perl and am looking for all tutorials
> available ... i need to use mysql
Perl has no members, so I am not sure how you'd create a members area.
Is this a concealed webbie question, and are you really asking how you
can create a "personalised" web site? If so, ask in one of the
comp.infosystems.www.* groups on the general techniques to do that
sort of thing. It is very well possible that you can simply download
some software from somewhere that does all you need it to do.
If you need to implement it yourself, you design the components (in a
language-agnostic manner) at a very high level. Then you decide on
what technology you will use, as far as each component can be serviced
by a pre-existing technology (RDBMS, Web server, CGI, server/client
side, DHTML, authentication schemes, encryption). And then, finally,
just before you write code, you decide on the language.
ObPerl:
If you then are still convinced that you "need to create" this in Perl
you should use either mod_perl on Apache, or the CGI module, depending
on earlier choices about technology. To talk to your MySQL RDBMS you
would need the DBI module and the DBD::mysql drivers for that module.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
Trading Post Australia | rich salesperson.
|
------------------------------
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 4276
***************************************