[22064] in Perl-Users-Digest
Perl-Users Digest, Issue: 4286 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 19 03:05:42 2002
Date: Thu, 19 Dec 2002 00:05:12 -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 Thu, 19 Dec 2002 Volume: 10 Number: 4286
Today's topics:
Re: comment on 2 or 4 spaces indentation (Kevin Cline)
Re: comment on 2 or 4 spaces indentation (Kevin Cline)
Control-C trap <t18_pilot@hotmail.spam.com>
Counter <branmh@cox-internet.com>
Re: Counter (Tad McClellan)
Re: eval + SIGPIPE = exitcode ? <goldbb2@earthlink.net>
Re: extracting data from a column <snotrocket88@hotmail.com>
Extracting last element from a list (Andrew Luke NESBIT)
Re: Extracting last element from a list <bart.lateur@pandora.be>
Re: Extracting last element from a list <jurgenex@hotmail.com>
Re: FTPing without Net::FTP <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: getstore not working - please help <bwalton@rochester.rr.com>
Re: Hashing several million rows of data <goldbb2@earthlink.net>
Re: help: perl script to make all DNA sequence Nmers? <goldbb2@earthlink.net>
Re: help: perl script to make all DNA sequence Nmers? <goldbb2@earthlink.net>
http:Authen module feasbility (URGENT) <ban_krupt@mail.hongkong.com>
Re: Is this a bug? (5.6.1 and 5.005.04) <ndronen@io.frii.com>
perl script to capture streaming audio <control153@NOSPAMyahoo.com>
Re: perl script to capture streaming audio <goldbb2@earthlink.net>
Re: RESIZE IMAGES PERL MODULES? <mgjv@tradingpost.com.au>
splitting array, each element holding multiple values i <hugo@geoinformex.com>
Re: stdin binary or text ? <goldbb2@earthlink.net>
Re: Tracking User's OS type? <jurgenex@hotmail.com>
While is the best for Perl win32? <hujirong888@hotmail.com>
Re: While is the best for Perl win32? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Why do beginners read files into an array? (Tad McClellan)
Re: Wierd loop/chdir behavior (Steve Walker)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Dec 2002 21:04:16 -0800
From: kcline17@hotmail.com (Kevin Cline)
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <ba162549.0212182104.1de9265c@posting.google.com>
Gary Fu <gfu@saicmodis.com> wrote in message news:<3DDE42CB.415D34CD@saicmodis.com>...
> Hi,
>
> My colleague uses emacs and had hard time to modify Perl program with 2 spaces
> indentation. He told me that 4 spaces indentation is standard for Perl and the
> tab in
> emacs will do that automatically.
It's trivial to change from 4 column indentation to 2 column indentation
in emacs.
However, I'm a vi user, don't use tab (may be
> expanded
> to different number of spaces on different editors), prefer with 2 spaces
> indentation
> (to save stroke and line spaces).
If you're scripts are going to be maintained for any length of time,
then worrying about key strokes is short-sighted. Don't make others
pay for your insistence on using an archaic text editor. Consider
using VIM instead.
> Any comment why 4 spaces indentation is standard or better than 2 spaces for
> Perl ?
Four spaces is better because it discourages nesting control constructs
too deeply. Two levels of nesting are enough for any one function.
------------------------------
Date: 18 Dec 2002 21:06:51 -0800
From: kcline17@hotmail.com (Kevin Cline)
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <ba162549.0212182106.4a3415d5@posting.google.com>
ctcgag@hotmail.com wrote in message news:<20021122113120.447$gh@newsreader.com>...
> 4 spaces is better because it makes it very obvious what level of
> indentation you are on. 2 spaces can be hard to visually align over a
> large page of text.
Your functions are too long.
> 2 spaces is better because 4 spaces per indent often
> leaves you with very little line left to code on if code is highly nested,
> which is common.
And too deeply nested. Consider breaking them up. Your readers
will thank you.
------------------------------
Date: Thu, 19 Dec 2002 04:51:00 GMT
From: "William Hymen" <t18_pilot@hotmail.spam.com>
Subject: Control-C trap
Message-Id: <UecM9.1594$X17.127706@newsread1.prod.itd.earthlink.net>
I have ActiveState perl on Wintel.
Can I trap control-C or control-Z in a loop
and "last" out of it?
Example would be great.
Thanks in advance-
Bill
------------------------------
Date: Wed, 18 Dec 2002 21:32:59 -0600
From: "Brandon Holland" <branmh@cox-internet.com>
Subject: Counter
Message-Id: <v02fhvnvpujed2@corp.supernews.com>
I found this counter script
----------------------------------------------------------------------------
----------
#!/usr/bin/perl
my($sec,$min,$hour,$mday,$mon,$year) = (localtime(time))[0,1,2,3,4,5];
$mon++; $year+=1900;
#Change Variables
$your_ip = "0.0.0.0";
$directory = "/home/brandon_holland/www/jupiter2/applications/stats/data/";
$print = '0';
$count = "$ENV{'DOCUMENT_NAME'}";
$log = "$ENV{'DOCUMENT_NAME'}.$year$mon$mday";
##############
#Script Begins
$shortdate = `date +"%D %T %Z"`;
chop ($shortdate);
if ($ENV{'REMOTE_ADDR'} eq $your_ip) {
}
else {
open (COUNT, "$directory$count");
$counter = <COUNT>;
close (COUNT);
open (COUNT, "> $directory$count");
$counter += 1;
print COUNT "$counter";
close (COUNT);
open (LOG, ">>$directory$log");
print "Content-type: text/plain\n\n ";
print LOG "Time: $shortdate\n";
print LOG "IP: $ENV{'REMOTE_ADDR'}\n";
print LOG "Host: $ENV{'REMOTE_HOST'}\n";
print LOG "With: $ENV{'HTTP_USER_AGENT'}\n";
print LOG "From: $ENV{'HTTP_REFERER'}\n";
print LOG "Page: $ENV{'DOCUMENT_NAME'}?$ENV{'QUERY_STRING'}\n\n";
close (LOG);
if ($print eq '1') {
print "$counter";
}
}
exit;
----------------------------------------------------------------------------
----------
works great, but is there a way to get the counter to offer minor protection
against
people reloading your page over and over to increase "hits". have the script
set up
so the same person cannot increase the counter until someone else loads the
page.
I also found this script.
----------------------------------------------------------------------------
----------
#!/usr/bin/perl
open(FILE, "+<./counter.dat");
flock(FILE, 2);
($number,$remote) = split(/:/, <FILE>);
$number++ if $remote ne "$ENV{'REMOTE_ADDR'}";
print "Content-type: text/html\n\n";
print "$number";
truncate(FILE, length("$number:$ENV{'REMOTE_ADDR'}"));
seek(FILE, 0, 0);
print FILE "$number:$ENV{'REMOTE_ADDR'}";
close(FILE);
exit();
----------------------------------------------------------------------------
----------
but I like the log feature of the first one. I have tried to combine the
first and the second
script together but the counter just doesn't increase with different
visitors, it justs updates
the ip address.. If you would like to see the combine script email at
branmh@cox-internet.com
and I will sent it to you.....
------------------------------
Date: Wed, 18 Dec 2002 22:25:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Counter
Message-Id: <slrnb02iid.54n.tadmc@magna.augustmail.com>
Brandon Holland <branmh@cox-internet.com> wrote:
> I found this counter script
It is worth less than you paid for it, I'm guessing.
> #!/usr/bin/perl
>
> my($sec,$min,$hour,$mday,$mon,$year) = (localtime(time))[0,1,2,3,4,5];
> $mon++; $year+=1900;
>
> #Change Variables
>
> $your_ip = "0.0.0.0";
> $directory = "/home/brandon_holland/www/jupiter2/applications/stats/data/";
> $print = '0';
> $count = "$ENV{'DOCUMENT_NAME'}";
> $log = "$ENV{'DOCUMENT_NAME'}.$year$mon$mday";
>
> ##############
> #Script Begins
The script began several lines *before* here...
> $shortdate = `date +"%D %T %Z"`;
> chop ($shortdate);
^^^^
^^^^
Looks like 7 year old Perl code.
> if ($ENV{'REMOTE_ADDR'} eq $your_ip) {
> }
>
> else {
That's pretty silly. You can replace the 4 lines above with
if ($ENV{'REMOTE_ADDR'} ne $your_ip) {
> open (COUNT, "$directory$count");
You should always, yes *always*, check the return value from open().
> $counter = <COUNT>;
> close (COUNT);
If the program loses its time slice here, the count could
become corrupted.
> open (COUNT, "> $directory$count");
> $counter += 1;
> print COUNT "$counter";
^ ^
Useless quotes.
> close (COUNT);
> works great,
No it doesn't.
You just have not observed it failing (yet).
It must use a file locking scheme if it is to run in a multitasking
enviroment (such as CGI) without the potential for corrupted data.
> but is there a way to get the counter to offer minor protection
> against
> people reloading your page over and over to increase "hits".
If they've reloaded it, then the hits _have_ increased.
> have the script
> set up
> so the same person cannot increase the counter until someone else loads the
> page.
There is no way of telling if it is the same person or not.
An IP address does not correlate to a person.
In the case of a proxy, there can be hundreds or thousands of
people all presenting the same IP address.
> I also found this script.
Somewhat better, but still "crufty".
This programmer did not know Perl very well either.
> #!/usr/bin/perl
>
> open(FILE, "+<./counter.dat");
You should always, yes *always*, check the return value from open().
> flock(FILE, 2);
File locking. This script does not have the same problem that
the first one has. It is a little better.
> ($number,$remote) = split(/:/, <FILE>);
>
> $number++ if $remote ne "$ENV{'REMOTE_ADDR'}";
^ ^
^ ^
A useless use of quotes. They do not do anything useful, so
they should not be there.
> print "Content-type: text/html\n\n";
> print "$number";
>
> truncate(FILE, length("$number:$ENV{'REMOTE_ADDR'}"));
That line introduces a bug.
If the new counter line is shorter that the the old one,
you'll have some unwanted bytes at the end.
> but I like the log feature of the first one. I have tried to combine the
> first and the second
> script together
You are taking two poor programs to create a third poor program.
> but the counter just doesn't increase with different
> visitors, it justs updates
> the ip address..
Can't fix unseen code, so I don't know what you've done wrong,
in addition to what the 2 original programmers did wrong.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 19 Dec 2002 02:13:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: eval + SIGPIPE = exitcode ?
Message-Id: <3E0171A7.AB1F3664@earthlink.net>
peter pilsl wrote:
[snip]
> eval {
> local $SIG{ALRM} = sub { die "alarm\n" };
> local $SIG{PIPE} = sub { die "pipe\n" };
Try setting $SIG{PIPE} to 'IGNORE'.
> alarm $timeout;
>
> if (open (DH,'| /usr/sbin/sendmail -f x@goldfisch.at y@goldfisch.at')) {
> while (my $line=<FH>) {print DH $line;}
If, as I suggested, you ignore SIGPIPE, then you need to test your
print statement for success (it could fail with EPIPE).
while( my $line = <FH> ) { print DH $line or last }
> close DH;
> }
> alarm 0;
> };
--
$..='(?:(?{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: Thu, 19 Dec 2002 02:11:59 GMT
From: "Rick L." <snotrocket88@hotmail.com>
Subject: Re: extracting data from a column
Message-Id: <OV9M9.68$Qm5.1304@paloalto-snr1.gtei.net>
"Steve Walker" <J_Steven_Walker@hotmail.com> wrote in message
news:534c971c.0212181743.e542d80@posting.google.com...
> (something you can run) ---
>
> #!/usr/bin/perl
> while (<>)
> {
> chop($line = $_) ;
> @linedata = split(" ",$line);
> $lineitem = $linedata[4];
> $lineitem =~ m/http:\/\/(.*):\d/ ;
> $url = $1;
> print "\n url is $url\n";
> }
> You can read 'em all or process line by line --
> either method will let you process each line as it is input if you
> wish
>
> good luck,
>
> S.
That is a great example and it works like a charm. I appreciate the help,
thanks.
------------------------------
Date: 19 Dec 2002 05:08:26 GMT
From: alnesbit@students.cs.mu.OZ.AU (Andrew Luke NESBIT)
Subject: Extracting last element from a list
Message-Id: <atrk8a$18h$1@mulga.cs.mu.OZ.AU>
Hi, I'm pretty new to Perl, and have the following question.
Consider the following code:
----------------------------------------------------------------------
#!/usr/bin/perl -w
my ($first, $last, @rest);
my @array = ("one", "two", "three");
($first, @rest) = @array;
print "First element is: $first\n";
(@rest, $last) = @array;
print "Last element is: $last\n";
----------------------------------------------------------------------
It gives the following output:
$ ./foo.pl
First element is: one
Use of uninitialized value at ./foo.pl line 10.
Last element is:
The statement which extracts the head and tail from @array seems
pretty idiomatic in Perl.
So, I thought I could extract the last element similarly (i.e., the
last two lines). But it doesn't seem to work. Why is this? And
what's the idiomatic way to do this operation?
BTW, I was trying to get the two "my" declarations merged into one
"my" declaration, but perl didn't seem to like any of my attempts. Is
this possible?
Thanks for any feedback.
Andrew.
------------------------------
Date: Thu, 19 Dec 2002 05:23:57 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Extracting last element from a list
Message-Id: <dkl20vosn68af9ckiesgqmvo68qjuha2f8@4ax.com>
Andrew Luke NESBIT wrote:
>(@rest, $last) = @array;
>print "Last element is: $last\n";
@rest gets everything, and $last the rest, i.e;, nothing. By result, it
becomes undef.
>It gives the following output:
>
>$ ./foo.pl
>First element is: one
>Use of uninitialized value at ./foo.pl line 10.
>Last element is:
>
>The statement which extracts the head and tail from @array seems
>pretty idiomatic in Perl.
>what's the idiomatic way to do this operation?
Using pop, or maybe splice, or a hash slice if you want it
non-destructive.
@rest = @array;
$last = pop @rest; # this alters @rest
or, same effect:
$last = splice @rest, -1;
Non-destructive:
$last = $rest[-1];
A few:
@last = @rest[-2, -1];
See also: shift (similar to your first example), and their counterparts,
unshift (<-> shift) and push (<->pop).
--
Bart.
------------------------------
Date: Thu, 19 Dec 2002 06:04:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Extracting last element from a list
Message-Id: <3kdM9.49681$4W1.37792@nwrddc02.gnilink.net>
Andrew Luke NESBIT wrote:
> Consider the following code:
[...]
> The statement which extracts the head and tail from @array seems
> pretty idiomatic in Perl.
>
> So, I thought I could extract the last element similarly (i.e., the
> last two lines). But it doesn't seem to work. Why is this? And
> what's the idiomatic way to do this operation?
You may want to look into "shift" and "pop":
perldoc -f shift
perldoc -f pop
jue
------------------------------
Date: Thu, 19 Dec 2002 06:26:23 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: FTPing without Net::FTP
Message-Id: <atroqf$m46$1@korweta.task.gda.pl>
In article <237aaff8.0212181334.796a9de3@posting.google.com>, krakle
wrote:
> "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
news:<atq65p$pmq$1@pheidippides.axion.bt.co.uk>...
>> I wonder why it is that on this newsgroup, when someone asks a question to
>> solve a particular problem they have, and someone else gives them a possible
>> solution, there are always a couple of "regulars" who pedantically state
>> that this is not the correct way of doing it in Perl and is therefore WRONG.
>
> Must expect this from a newsgroup full of dorks. I once posted a
> rather simple question pertaining to using mySQL with Perl and was
> told it wasn't a perl question even though it would make no sense to
> ask a Perl coding question in a mySQL group.
I'll bet anything that you asked a mySQL question, not a Perl
question and were too stupid to realise it.
> I was also once told that this isn't the place to ask questions. Last
> I checked 97% of these postings have questions.
You were probably told that this is the place to discuss Perl, but
were too stupid to realise it.
>> In this case, the original poster was writing a perl script that does a
>> rather simple task, and wanted to know how to do an FTP transfer without
>> using the Net::FTP module.
>
> Like I said this newsgroup is full of morons. He asked how to do a FTP
> task WITH OUT Net::Ftp and the majority of answers were "Install Net
> ftp".
Let's summarise:
a. This group is *full* of morons,
b. You read this group.
Now what do you think that says about you? Take your time.
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 19 Dec 2002 02:44:08 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: getstore not working - please help
Message-Id: <3E013269.6040804@rochester.rr.com>
Dennis Macdonald wrote:
> THanks for your help. In deed it does work, but puts the file on my
> web server. What I was after is to scrpit the download to a user not
> onto the server. Do you know how to do this. I seem to be totally
> off-beam with this one.
...
> Dennis.
>
Well, um, are you running the script on the computer to which you want
to download the file, or are you running it on your web server? It will
be downloaded to the computer on which the script is executed. And
also, to the directory where the script is located, unless you specify
otherwise in the "local" file name argument to getstore.
--
Bob Walton
------------------------------
Date: Wed, 18 Dec 2002 23:33:15 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Hashing several million rows of data
Message-Id: <3E014C0B.B3FF33E4@earthlink.net>
ctcgag@hotmail.com wrote:
[snip]
> my @errors = qx[ awk '{print $2}' big_file |sort|uniq -d ];
> die "Found duplicate entries for @errors" if @errors;
This has nothing to do with perl, but...
cut -f 2 -d " "
Might be more efficient than:
awk '{print $2}'
--
$..='(?:(?{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: Thu, 19 Dec 2002 01:17:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: help: perl script to make all DNA sequence Nmers?
Message-Id: <3E016484.6D63680F@earthlink.net>
isen wrote:
>
> does anyone have a perl script to make all possible DNA sequence Nmers
> (and put in an array preferably) when given N as an input? Please
> reply by email (sindriATmacDOTcom) if possible.
Assuming that an 'Nmer' is a sequence N codons long...
my @acids = qw(A T C G);
my $N = shift(@ARGV);
my @Nmers;
my $count = "";
local $" = "";
until( vec $count, $N, 2 ) {
push @Nmers, "@acids[map vec($count, $_, 2), 0 .. $N-1]";
} continue {
my $i = 0; 1 until ++vec $count, $i++, 32;
}
# deal with @Nmers.
__END__
--
$..='(?:(?{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: Thu, 19 Dec 2002 02:06:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: help: perl script to make all DNA sequence Nmers?
Message-Id: <3E016FE3.26B0F4DB@earthlink.net>
ctcgag@hotmail.com wrote:
>
> isen@molbio.mgh.harvard.edu (isen) wrote:
> > does anyone have a perl script to make all possible DNA sequence
> > Nmers (and put in an array preferably) when given N as an input?
>
> warn "Untested Code";
> sub Nmer {
> die unless $_[0];
> return qw/A C T G/ if $_[0]==1;
> return map {$_.'A', $_.'C', $_.'T', $_.'G'} Nmer($_[0]-1);
> };
This puts everything on the stack -- kinda wasteful of memory, ne?
--
$..='(?:(?{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: Thu, 19 Dec 2002 10:58:24 +0800
From: "Ban" <ban_krupt@mail.hongkong.com>
Subject: http:Authen module feasbility (URGENT)
Message-Id: <atrc1s$t79$1@news.ctimail.com>
Hi all,
I am now finding a way to "help" user to enter a htaccess protected resource
by using a CGI query to database and submit to that particular protected
website with username/password.
Can Http:Authen solve this problem?
Please help becoz I am in a hurry.
Thanks to all.
Ban
------------------------------
Date: 19 Dec 2002 02:32:53 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: Is this a bug? (5.6.1 and 5.005.04)
Message-Id: <3e012fd5$0$16020$75868355@news.frii.net>
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> You might try writing it this way (untested):
> sub load_running_users {
> my ($self) = @_;
> return &{ $self->{load_running_user_func} };
> }
Ah, much better. The doc reference and your code clicked.
Thanks, Joe.
Nicholas
--
Please do not reply to USENET posts, at least to mine, by email.
------------------------------
Date: Thu, 19 Dec 2002 06:10:44 GMT
From: opt cool dude <control153@NOSPAMyahoo.com>
Subject: perl script to capture streaming audio
Message-Id: <Xns92E9C67C2D1Fcontrol153NOSPAMyaho@167.206.3.2>
hi guys
need some serious help...
i need to capture streaming audio from a web site and save it on my local
drive. i don't know where to start ??? i tried with lwp but no help... can
someone point me in the right direction ??? any ideas ??
------------------------------
Date: Thu, 19 Dec 2002 02:08:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: perl script to capture streaming audio
Message-Id: <3E01707D.E916D0A1@earthlink.net>
opt cool dude wrote:
>
> hi guys
> need some serious help...
>
> i need to capture streaming audio from a web site and save it on my
> local drive. i don't know where to start ??? i tried with lwp but no
> help... can someone point me in the right direction ??? any ideas ??
Streaming audio is done using a special network protocol.
Well, actually, there are a number of streaming audio network protocols.
Find some documentation defining the protocol for the particular audio
stream you want to download, give us a url, and perhaps we can help you.
--
$..='(?:(?{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: Thu, 19 Dec 2002 18:40:33 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: RESIZE IMAGES PERL MODULES?
Message-Id: <slrnb02tvh.aid.mgjv@martien.heliotrope.home>
On Mon, 16 Dec 2002 07:52:09 +0000,
Dave Cross <dave@dave.org.uk> wrote:
> On Mon, 16 Dec 2002 08:43:48 +0100, Federico Bari wrote:
>
>> Hi All,
>>
>> do somebody know if perl modules for resizing images exist??? Thank you
>> very much,
>
> Perl has modules that interface to both GD and ImageMagick. You'll find
> them at CPAN <http://search.cpan.org/>.
And apart from those 2, Imager is also available, and quite usable.
Martien
--
|
Martien Verbruggen | System Administration is a dirty job, but
| someone said I had to do it.
|
------------------------------
Date: Thu, 19 Dec 2002 15:54:54 +0800
From: hugo <hugo@geoinformex.com>
Subject: splitting array, each element holding multiple values into array with single values
Message-Id: <3E017B4E.7080603@geoinformex.com>
Hi
I have a problem I don't seem to be able to solve.
I have a cgi script creating a page with a form containing a series of
text boxes, each box containing a multi-selection list.
When the form is forwarded I get the values out as follows:
for ($i = 0; $i < $projectlimit; $i++) {
$P[$i] = join ' ' => $query->param("company_projects$i");
}
so that I end up with an array, each array element containing a set of
values.
However, I would like to split the values into another array which,
presumably, has to be two dimensional. In other words, if my array @P
contains
$P[0] = "A B C D";
$P[1] = "X Y Z";
then my new array should be:
$NP[0][0] = "A";
$NP[0][1] = "B";
$NP[0][2] = "C";
$NP[0][3] = "D";
$NP[1][0] = "X";
$NP[1][1] = "Y";
$NP[1][2] = "Z";
How can I do this?
Any help, particularly a code example would be most welcome.
Thanks
Hugo
--
Dr Hugo Bouckaert
Systems and Programming Engineer
GeoInformatics Exploration Australia P/L
57 Havelock St
West Perth, WA 6005
PO Box 1675, West Perth 6872
Ph: 61 08 9420 7400
Fax: 61 08 9226 1299
www.geoinformex.com
------------------------------------------------------------------------
This email and any attachments may be confidential or legally
privileged. If you received this message in error or are not the
intended recipient, you should destroy the e-mail message and any
attachments or copies, and you are prohibited from retaining,
distributing, disclosing or using any information contained herein.
Please inform us of the erroneous delivery by return e-mail. Thank you
for your cooperation.
------------------------------
Date: Thu, 19 Dec 2002 02:25:09 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: stdin binary or text ?
Message-Id: <3E017455.A26A7C59@earthlink.net>
cedric wrote:
>
> Hi !
> I would like to know if in perl stdin is opened in binary or text
> mode?
In the absence of -Mopen=..., perl's stdin is opened in text mode.
This means, if you're on dos/windows, any CRLF that's read from stdin in
will appear in the string as just "\n".
And if you're on the newest versions of RedHat (or something else which
sets $ENV{LANG}), and if you're using perl5.8, then text mode means that
stdin is UTF8.
> And if in a text stream every forms of newlines will be converted to a
> single \n ?
Yes.
> Because I have a dos file with \r\n and, reading it through stdin, \n
> does not seam to math \r\n but only \n ...
Yes. Text mode on dos/win means that if the file contains \015\012,
perl won't see that, but will instead see just "\n".
--
$..='(?:(?{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: Thu, 19 Dec 2002 03:31:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Tracking User's OS type?
Message-Id: <O4bM9.48741$4W1.26707@nwrddc02.gnilink.net>
John wrote:
> I recently created a website and I am able to do the following:
>
> Track IP Address, browser, etc.
>
> However, I can't seem to find how to track what OS the user is using.
> Is there a simple line of perl code that will accomplish this?
Please see "perldoc perlvar":
$OSNAME
$^O The name of the operating system under which this copy of Perl
was built, as determined during the configuration process. The
value is identical to "$Config{'osname'}". See also the Config
manpage and the -V command-line switch documented in the perlrun
manpage.
Although this doesn't tell you the users OS at least it will give you some
good indication because it's highly unlikely that e.g. a Perl version
compiled on a McIntosh is being used on a Sun workstation.
Of course when someone installs ActiveState Perl then you will always get
MSWin32. You need to decide if this good enough for your application or if
you need to distinguish between e.g. Win95, NT3, and XP.
jue
------------------------------
Date: Thu, 19 Dec 2002 13:56:47 +0800
From: "Hu Ji Rong" <hujirong888@hotmail.com>
Subject: While is the best for Perl win32?
Message-Id: <atrmhg$792$1@reader01.singnet.com.sg>
new to Perl.
------------------------------
Date: Thu, 19 Dec 2002 06:36:20 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: While is the best for Perl win32?
Message-Id: <atrpd4$m46$2@korweta.task.gda.pl>
Subject: While is the best for Perl win32?
I think "for" is better myself.
In article <atrmhg$792$1@reader01.singnet.com.sg>, Hu Ji Rong wrote:
> new to Perl.
What is it exactly you're trying to tell/ask us? Are you looking for a
Perl distro for Windoze? If that's the case try:
http://www.activestate.com/
If that's *not* the case you'll have to be a bit clearer.
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 18 Dec 2002 20:35:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why do beginners read files into an array?
Message-Id: <slrnb02c4d.4h5.tadmc@magna.augustmail.com>
Ian.H [dS] <ian@WINDOZEdigiserv.net> wrote:
> open(FILE, "<data.txt");
You should always, yes *always*, check the return value from open():
open(FILE, 'data.txt') or die "could not open 'data.txt' $!";
> echo $_;
perldoc -f echo
No documentation for perl function `echo' found
Done too much shell programming lately? :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Dec 2002 20:43:18 -0800
From: J_Steven_Walker@hotmail.com (Steve Walker)
Subject: Re: Wierd loop/chdir behavior
Message-Id: <534c971c.0212182043.372f3e1f@posting.google.com>
Anno - up front - thanks for checking in. I will attempt to clarify
> You should always check the result of open(). A prior test for
> existence is no replacement, for various reasons.
Agreed but this was supposed to be a quick prototype to verify the
concept with polish added later. 'Quick' has become gruesomely
slow...
> >
> > while (<CONF>)
> > {
> > @build = split(/[:\n]/,$') if m/^\s?BuildPath\s?=/ ;
> > @active = split(/[:\n]/,$') if m/^\s?ActivePath\s?=/ ;
> > @web = split(/[:\n]/,$') if m/^\s?WebPath\s?=/ ;
> > @newdata = split(/[:\n]/,$') if m/^\s?NewDataPath\s?=/ ;
>
> It would be interesting to know if these lists contain fully qualified
> or relative path names.
>
For the current effort only ActivePath was relative. All others $HOME
paths as indicated in the sample config input
[repeated]
BuildPath=~/Data/build
ActivePath=Data/active
NewDataPath=~/epaa:~/epab:~/epac:~/epaa:~/epab:~/epac
WebPath=~/clhtml
> > # Wierdness starts here
> >
> > TOP: chdir $work_dir ;
> > $ddir=shift @newdata;
> > print "New Scan data at $ddir\n";
> > if (chdir(glob "$ddir"))
> ^ ^
> Those quotes are unnecessary.
>
> > {
>
> So now you are in the directory glob() made out of $ddir...
Well, yes and no. It depends on which pass of the loop you are in.
If you check out the included output list you will see that the first
pass handles the first two entries in the list and produces the
desired absolute path to the data that the symbolic links in the
config file and home directory point to. In the second pass the next
two entries are processed but it appears that the chdir never happens
so the pwd returns only the home directory that we started in. Then
the last pass processes the final two entries and succeeds just as the
first pass did.
if you cut the contents of loop down to a single entry per pass the
same pattern of succeed/fail emerges with the correct behavior for
entries 1,3, and 5 and entries 2,4, and 6 never making it into the
intended directory.
>
> > chop($pwd=`/usr/bin/pwd`);
> > print "now in $ddir ($pwd)\n" ;
> > $dp .= " $pwd" ;
>
> ...as the printout probably verifies.
>
> > chdir $ddir;
>
> Here, you are trying again to change your directory to $ddir, this time
> without a glob(). If the glob() was needed in the first place, you'll
> need it here too. If what it returns is an absolute path, then this
> second chdir should succeed (with, possibly, a glob added). If it's a
> relative path, it is now interpreted from the changed working directory
> and cd() will fail, except under unusual circumstances.
Agreed and if I had not already encountered the failure this would not
be here but I stuck it in since this particular test has a valid
absolute if symbolic path. The same sort of reasoning was in play
when I doubled the processing occuring in any given loop. I was
hoping to uncover some sort of clues on the behavior of chdir or chdir
in conjunction with a loop, but all I found out was that everything in
a given pass through the loop either succeeds or fails.
Either there is some fundamental subtlety of perl that I am stepping
on unawares (ie. I screwed up) or there is some sort of bug here. My
point in posting is to see if anybody has experienced this. If this
is not reproduceable on anybody elses machine it may be something
about the platform I am using that creates the problem.
Thanks again for giving it a once over...
Regards,
S.
------------------------------
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 4286
***************************************