[29691] in Perl-Users-Digest
Perl-Users Digest, Issue: 935 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 14 11:09:42 2007
Date: Sun, 14 Oct 2007 08:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 14 Oct 2007 Volume: 11 Number: 935
Today's topics:
Re: a nice little perl utility <zaxfuuq@invalid.net>
Re: Displaying hex numbers as decimal? <joe@inwap.com>
Help: Filemask problem <openlinuxsource@gmail.com>
Re: Help: Filemask problem <openlinuxsource@gmail.com>
Re: Help: Filemask problem <mgjv@tradingpost.com.au>
Re: Help: Filemask problem <tadmc@seesig.invalid>
Re: Help: Filemask problem <openlinuxsource@gmail.com>
Re: net:scp Host key verification failed <joe@inwap.com>
Re: optimal vs. optimized [was: Re: string concatentati <teachingvocabulary@gmail.com>
Passing Post Params & Object Reference ? <wheeledBob@yahoo.com>
Re: Passing Post Params & Object Reference ? <noreply@gunnar.cc>
Re: quotes difference in Perl5.6 vs 5.8 <stoupa@practisoft.cz>
Re: UTF8 strings and filesystem access <hjp-usenet2@hjp.at>
Re: Windows,ASSOC,FTYPE,.pl,.plx,.sh <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 13 Oct 2007 17:12:16 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: a nice little perl utility
Message-Id: <L-WdnfsV8OZVzYzanZ2dnUVZ_hSdnZ2d@comcast.com>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:fe61h3h875jgp19btjts1crl9pfbgvd00e@4ax.com...
> On Fri, 12 Oct 2007 14:44:20 -0700, "Wade Ward" <zaxfuuq@invalid.net>
> wrote:
>
>>> I'm ASTONISHED!! Why on hell do you need to do that?!?
>>Here, on hell, I found myself doing the same things time and time again.
>>It
>>saves 35 keystrokes to get to where my command window has to be.
>
> The point is, you should not need the 35 keystrokes in the first
> place.
I no longer do. I tried to use the komodo IDE but couldn't get anything off
the ground as a beginner. It was a huge waste of time for me. Not that the
product is necessarily bad; I'm just nowhere near where I can use something
like that yet.
>>> C:\temp>merl crank
>>> Merl iz a crank!
>>>
>>> C:\temp>merl
>>> Merl iz a freak!
>>I'll take that as a compliment.
>
> You should take it as an example.
I finally got my head around this and came up with another example:
http://www.zaxfuuq.net/perl7.htm
--
wade ward
"Nicht verzagen, Bruder Grinde fragen."
------------------------------
Date: Sun, 14 Oct 2007 04:31:18 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Displaying hex numbers as decimal?
Message-Id: <EaydnUthF4aGY4zanZ2dnUVZ_s-pnZ2d@comcast.com>
faren451@gmail.com wrote:
> EB 70 07 8A 51 C5 98 1B 01 00 00 00 00 00 00 02 00 00
> 00 00 00 00 00 00 00 01 01 00 01 00 00 00 00 00 00
> 00 02 00 00 00 01 00 01 01 00 01 02 00 00 00 00 00
> 01 00 01 00 00 93 10 60 00
>
> I appreciate any help! I am a completely Perl newbie, so I have no
> idea why this will not work. The built-in hex() function also does
> not work, I suspect for the same reason?
The built-in hex() function works just fine.
#!/usr/bin/perl
use strict; use warnings;
while (<DATA>) {
print " $_"; # Leading blank to make columns line up
foreach my $hnum (/[A-Fa-f0-9]+/g) {
printf "%3d ",hex($hnum);
}
print "\n\n";
}
__DATA__
EB 70 07 8A 51 C5 98 1B 01 00 00 00 00 00 00 02 00 00
00 00 00 00 00 00 00 01 01 00 01 00 00 00 00 00 00
00 02 00 00 00 01 00 01 01 00 01 02 00 00 00 00 00
01 00 01 00 00 93 10 60 00
The output is:
EB 70 07 8A 51 C5 98 1B 01 00 00 00 00 00 00 02 00 00
235 112 7 138 81 197 152 27 1 0 0 0 0 0 0 2 0 0
00 00 00 00 00 00 00 01 01 00 01 00 00 00 00 00 00
0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0
00 02 00 00 00 01 00 01 01 00 01 02 00 00 00 00 00
0 2 0 0 0 1 0 1 1 0 1 2 0 0 0 0 0
01 00 01 00 00 93 10 60 00
1 0 1 0 0 147 16 96 0
-Joe
------------------------------
Date: Sun, 14 Oct 2007 19:44:35 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: Filemask problem
Message-Id: <pan.2007.10.14.11.44.35.585988@gmail.com>
Hello,
I write a perl script to show the file mask like -rwxr-xr-x is 0755, but
when I run my script, it shows 835 in this mode. I don't know why.
There's my code:
#!/usr/bin/perl -w
if (@ARGV == 0)
{
die "Usage: filemask.pl <filename(s)>\n";
}
if (@ARGV != 0)
{
foreach $file (@ARGV)
{
unless (-e $file)
{
print "***Error: $file dose not exist.\n";
next;
}
unless (-r $file)
{
print "***Error: Cannot read $file.\n";
next;
}
my($mode) = stat($file);
print "$file ==> $mode\n";
}
}
Could you tell me how to solve this?
Thank you very much~
Regards,
Amy Lee
------------------------------
Date: Sun, 14 Oct 2007 19:55:35 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Filemask problem
Message-Id: <pan.2007.10.14.11.55.34.565124@gmail.com>
On Sun, 14 Oct 2007 19:44:35 +0800, Amy Lee wrote:
> Hello,
>
> I write a perl script to show the file mask like -rwxr-xr-x is 0755, but
> when I run my script, it shows 835 in this mode. I don't know why.
>
> There's my code:
>
> #!/usr/bin/perl -w
>
> if (@ARGV == 0)
> {
> die "Usage: filemask.pl <filename(s)>\n";
> }
> }
> if (@ARGV != 0)
> {
> foreach $file (@ARGV)
> {
> unless (-e $file)
> {
> print "***Error: $file dose not exist.\n"; next;
> }
> unless (-r $file)
> {
> print "***Error: Cannot read $file.\n"; next;
> }
> my($mode) = stat($file);
> print "$file ==> $mode\n";
> }
> }
> }
> Could you tell me how to solve this?
>
> Thank you very much~
>
> Regards,
>
> Amy Lee
I change this part:
my($mode) = stat($file); to
my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks) = stat($file);
However, it's useless, what happened?
Thanks,
Amy Lee
------------------------------
Date: Sun, 14 Oct 2007 22:07:13 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Help: Filemask problem
Message-Id: <slrnfh41jh.b5o.mgjv@martien.heliotrope.home>
On Sun, 14 Oct 2007 19:55:35 +0800,
Amy Lee <openlinuxsource@gmail.com> wrote:
> On Sun, 14 Oct 2007 19:44:35 +0800, Amy Lee wrote:
>
>> Hello,
>>
>> I write a perl script to show the file mask like -rwxr-xr-x is 0755, but
>> when I run my script, it shows 835 in this mode. I don't know why.
[snip]
>> my($mode) = stat($file);
>> print "$file ==> $mode\n";
> I change this part:
>
> my($mode) = stat($file); to
>
> my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
> $ctime, $blksize, $blocks) = stat($file);
>
> However, it's useless, what happened?
Print the mode in octal. The permissions you refer to above are octal
numbers, but you print them in decimal.
#!/usr/bin/perl
use warnings;
use strict;
for my $f (@ARGV)
{
my ($mode) = (stat $f)[2];
printf "$f: %o\n", $mode;
}
Martien
--
|
Martien Verbruggen |
| The gene pool could use a little chlorine.
|
------------------------------
Date: Sun, 14 Oct 2007 12:30:15 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help: Filemask problem
Message-Id: <slrnfh42pj.nmn.tadmc@tadmc30.sbcglobal.net>
Amy Lee <openlinuxsource@gmail.com> wrote:
> I write a perl script to show the file mask like -rwxr-xr-x is 0755,
> There's my code:
>
> #!/usr/bin/perl -w
[ snip 20 lines that are not needed to illustrate the problem ]
> my($mode) = stat($file);
> print "$file ==> $mode\n";
> Could you tell me how to solve this?
As with most of the questions that you post here, you can solve it
by reading the documentation for the function that you are using:
perldoc -f stat
...
Because the mode contains both the file type and its permissions,
you should mask off the file type portion and (s)printf using a
"%o" if you want to see the real permissions.
$mode = (stat($filename))[2];
printf "Permissions are %04o\n", $mode & 07777;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 14 Oct 2007 21:34:58 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Filemask problem
Message-Id: <pan.2007.10.14.13.34.57.902446@gmail.com>
Thank you very much~
I've solved this problem, thanks really~
Regards,
Amy Lee
------------------------------
Date: Sun, 14 Oct 2007 04:06:22 -0700
From: Joe Smith <joe@inwap.com>
To: Ivan Kohler <ivan-netscp_pod@420.am>
Subject: Re: net:scp Host key verification failed
Message-Id: <4711F82E.7050401@inwap.com>
lerameur wrote:
> now I get an error when I am quitting:
>
> Can't locate object method "quit" via package "Net::SCP" (perhaps you
> forgot to load "Net::SCP"?) at ./ftptest.pl line 36.
> line 36: $scp->quit;
>
> this looks like a valid command from http://perldoc.net/Net/SCP.pm
> there is also a nice tutorial on generating the keys at
> http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html
http://search.cpan.org/src/IVAN/Net-SCP-0.07/SCP.pm
Documentation error. There is no quit() method.
The last line of "#Net::FTP-style" in the SYNOPSIS should say
"There is no need to call a quit() method since the connection is not kept open."
-Joe
------------------------------
Date: Sat, 13 Oct 2007 22:41:56 -0700
From: teachingvocabulary <teachingvocabulary@gmail.com>
Subject: Re: optimal vs. optimized [was: Re: string concatentation...]
Message-Id: <1192340516.283322.93750@z24g2000prh.googlegroups.com>
> Even though you are using the news client of the clueless,
> groups.google.com, you can avoid being tarred with that brush if you
> learn how to use it. One of the most important is to snip away all but
> those sections of the original post except those necessary and germane
> to you response. Quoting the whole original post only to add your own
> tiny bit to the end is unnecessary and, in fact, rude.
Right. though that was not my point.
I wanted to tell about teaching vocabulary. I teach vocabulary to
students and take help of different sites. Some of them like
www.ultimatevocabulary.com
www.vocabularysoftware.net
www.buildingvocabulary.org
www.ultimatespelling.com
www.vocabularybuilder.info
------------------------------
Date: Sun, 14 Oct 2007 03:27:22 GMT
From: still me <wheeledBob@yahoo.com>
Subject: Passing Post Params & Object Reference ?
Message-Id: <vv13h35bjfei71199dr7vd4tnbj34td2fa@4ax.com>
I am using LWP to do a POST. I need some help automating the passing
of parameters and getting the object reference to work.
Here's the (hard coded) version that works fine;
my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
works']););
What I'd like to do is to set up an array (or hash) with the parameter
names and values so that I can change the parameters to be passed as
simply by altering the hash names/values. Then I'd just generate the
passed parameter string for as many values as are in the array.
Here's a hardcoded sample (no array for simplicity) that I tried as a
test just to figure out how to get the parameters passed:
my $param1 = "'test1'=>'001',";
my $param2 = "'test2'=>'002'";
my $response = $browser->post( $url,[$param1, $param2]);
But, it didn't pass the parameters. I assume that's because I
destroyed the object reference by doing what I did, but I don't
understand Perl objects and variable translation enough to know how to
construct a working object reference.
Thanks for any help,
------------------------------
Date: Sun, 14 Oct 2007 05:52:49 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Passing Post Params & Object Reference ?
Message-Id: <5ndi4tFhkjs1U1@mid.individual.net>
still me wrote:
> I am using LWP to do a POST. I need some help automating the passing
> of parameters and getting the object reference to work.
>
> Here's the (hard coded) version that works fine;
> my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
> works']););
>
> What I'd like to do is to set up an array (or hash) with the parameter
> names and values so that I can change the parameters to be passed as
> simply by altering the hash names/values. Then I'd just generate the
> passed parameter string for as many values as are in the array.
>
> Here's a hardcoded sample (no array for simplicity) that I tried as a
> test just to figure out how to get the parameters passed:
>
> my $param1 = "'test1'=>'001',";
> my $param2 = "'test2'=>'002'";
> my $response = $browser->post( $url,[$param1, $param2]);
Try this:
my %params = ( test1 => '001', test2 => '002' );
my $response = $browser->post( $url, [ %params ] );
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 14 Oct 2007 03:32:55 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: quotes difference in Perl5.6 vs 5.8
Message-Id: <ferrrl$m99$1@ns.felk.cvut.cz>
Ben Morrow wrote:
> Quoth "Petr Vileta" <stoupa@practisoft.cz>:
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> my $var = "abcd'efg";
>> open OUT, "> log.txt" or die("You stupid!");
>> print OUT "$var\n";
>> close OUT;
>>
>> This work in Perl 5.6.1 but fail in 5.8.0, but if I change this
>
> Don't use 5.8.0. It is very buggy. You should upgrade to 5.8.1 if at
> all possible.
>
Thank you for confirmation of my suspicion :-) I never installed Perl 5.8.0
but admin on some hosting server do it ;-( I wrote scripts for Perl 5.6.1
and these run fine on many hosting servers on different Perl's. I never see
as many troubles as on this hosting.
>> print OUT "$var\n";
>> to this
>> print OUT $var, "\n";
>> then this work in both Perl versions.
>
> I *seriously* doubt this makes any difference... I think it's more
My thinks are the same. This must be the same if Perl is not buggy, or
server not fail randomly.
[...]
> What is STDERR open to?
I don't know ;-) Maybe is redirected somewhere to user error-log file, to
some parser script, really don't know.
I not redirect STDERR anywhere in my script except in SIGPIPE handler.
> What happens if you set $SIG{PIPE} to 'IGNORE' and check the return
> value of all your print statements?
This is impossible. I grab html code from web pages, parse it and store to
database. If I ignore SIGPIPE then I can store wrong data to database. I
must be sure that data are OK or exit from script.
> What happens if, instead of this, you install your SIGPIPE handler
> with POSIX::sigaction, which will bypass safe signals; something like
>
I did not know this, I will take a look to it. I'm trying to not use POSIX,
because many functions are not multiplatform and my scripts are running on
Linux and Windows servers too.
Thanks for your tips.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Sun, 14 Oct 2007 15:33:24 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: UTF8 strings and filesystem access
Message-Id: <slrnfh46l5.6q4.hjp-usenet2@zeno.hjp.at>
On 2007-10-11 22:22, Gary E. Ansok <ansok@alumni.caltech.edu> wrote:
> In article <slrnfgt1r0.o12.hjp-usenet2@zeno.hjp.at>,
> Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>>> Quoth ansok@alumni.caltech.edu (Gary E. Ansok):
>>>>
>>>> 1) $dir is encoded internally in UTF8 (even if $dir doesn't
>>>> contain any non-ASCII characters)
>>
>>Then why is it a wide string?
>
> It's read in using XML::Simple from a config file that does not
> contain any non-ASCII characters, or any encoding specification in
> the XML prolog (though adding "encoding='ISO-8859-1'" didn't help).
The prolog really can't (or at least shouldn't) make any difference: It
specifies how the file is encoded, but the result of parsing the file is
always text which possibly contains wide characters.
You should decide whether you want to treat filenames as text or as
byte strings within your script.
If you want to treat them as text (e.g. because you want to do
operations like case-mapping, substrings, etc. on them), explicitely
encode them with the local character set just before using them in open,
stat, etc.
$dir_as_text = $xml_simple->{foo}{dir};
$filename_as_text = $xml_simple->{foo}{bar}[42]{title};
$filename_as_text = lc(substr($filename_as_text, 0, 20));
$filename_as_text = "$dir_as_text/$filename_as_text.pdf";
$filename_as_bytes = encode('us-ascii', $filename_as_text);
open($fh, '<', $filename_as_bytes);
If you want to treat them as byte strings, explicitely encode any text
string you get from a different source (in your case, from an XML file)
as early as possible.
$dir_as_bytes = encode('us-ascii', $xml_simple->{foo}{dir});
$filename_as_bytes = "$dir_as_text/$basename_as_bytes.pdf";
open($fh, '<', $filename_as_bytes);
> Now that I've dug a little deeper, I think upgrading some of our
> module versions may help avoid this problem -- a recent change to
> XML::LibXML mentioned "strip-off UTF8 flag for consistent behavior
> independent of document encoding".
You omitted an important piece here: The entry reads
"strip-off UTF8 flag with $node->toString($format,1) for consistent ..."
$node->toString returns a piece of XML, which always should be a series
of bytes, not characters. I haven't looked at the source code of
XML::Simple, but it probably uses $text->data or $node->nodeValue.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 13 Oct 2007 23:26:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Windows,ASSOC,FTYPE,.pl,.plx,.sh
Message-Id: <hat7u4-m22.ln1@osiris.mauzo.dyndns.org>
Quoth "Jim Carlock" <anonymous@127.0.0.1>:
> Perl is already installed. I just want a fully enabled cmd prompt,
> but I don't want to go through the GLOBAL changes that FTYPE and
> ASSOC apply. Environmental variables are locally maintained within
> a cmd prompt, meaning if you change one of those, they only affect
> that particular cmd prompt and NONE of the others that are already
> open and that open in the future. I'm wondering if there's a way to
> get an association to take effect without GLOBALLY producing the
> association.
No.
> It's 100% a problem to Windows NT and possibly Windows 9x. In effect,
> it's more of learning how to work with a cmd prompt than it is any-
> thing else. I was hoping someone within the Perl group delt with it
> in the past and knew of an answer.
However, it is not in any way a Perl (or perl) question, so please take
it elsewhere.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 935
**************************************