[25493] in Perl-Users-Digest
Perl-Users Digest, Issue: 7737 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 4 14:05:21 2005
Date: Fri, 4 Feb 2005 11:05:11 -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 Fri, 4 Feb 2005 Volume: 10 Number: 7737
Today's topics:
[perl-python] get web page programatically <xah@xahlee.org>
Array reference not consistently interpolating <evillen@innocent.com>
Re: Array reference not consistently interpolating <1usa@llenroc.ude.invalid>
Re: Array reference not consistently interpolating <noreply@gunnar.cc>
Equality of hashref objects <please_post@nomail.edu>
Re: Equality of hashref objects <jl_post@hotmail.com>
Re: Equality of hashref objects <skuo@mtwhitney.nsc.com>
Re: Equality of hashref objects <nobull@mail.com>
Re: Finding disk space used by Windows or Unix director <jurgenex@hotmail.com>
Re: Finding disk space used by Windows or Unix director <noreply@gunnar.cc>
Re: Finding disk space used by Windows or Unix director <rasto@gmx.at>
Re: Google Groups posters, please read <do-not-use@invalid.net>
Re: PAR/PP on Windows XP with ActiveState <bart.lateur@pandora.be>
Re: Regex: Selectively choose result group? <noreply@gunnar.cc>
Re: Regex: Selectively choose result group? (Anno Siegel)
Re: Regex: Selectively choose result group? <rasto@gmx.at>
Re: Regular expression woes <rasto@gmx.at>
Re: Regular expression woes (News)
Re: Regular expression woes <usereplytoinstead@innoline-systemtechnik.de>
Re: Regular expression woes <exjxw.hannivoort@interxnl.net>
Re: Regular expression woes <usereplytoinstead@innoline-systemtechnik.de>
Re: Regular expression woes <exjxw.hannivoort@interxnl.net>
Re: Socket programming blunders.... xhoster@gmail.com
why the variable become local? ai2003lian@yahoo.com
Re: why the variable become local? <msporleder@gmail.com>
Re: why the variable become local? <1usa@llenroc.ude.invalid>
Re: why the variable become local? <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Feb 2005 11:01:10 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] get web page programatically
Message-Id: <1107543599.362575.210730@o13g2000cwo.googlegroups.com>
# -*- coding: utf-8 -*-
# Python
# suppose you want to fetch a webpage.
from urllib import urlopen
print
urlopen('http://xahlee.org/Periodic_dosage_dir/_p2/russell-lecture.html').r=
ead()
# note the line
# from <library_name> import <function_name1,function_name2...>
# it reads the library and import the function name
# to see available functions in a module one can use "dir"
# import urllib; print dir(urllib)
# for more about this module import syntax, see
# http://python.org/doc/tut/node8.html
#---------------------
# sometimes in working with html pages, you need to creat links
# In url, some chars need to be encoded.
# the "quote" function does it. "unquote" function reverses it. Very
nice.
from urllib import quote
print quote("~joe's home page")
print 'http://www.google.com/search?q=3D' + quote("m=E9nage =E0 trois")
# (rely on the French to teach us interesting words)
# for more about the urllib module, see
# http://python.org/doc/lib/module-urllib.html
----------------------------
in perl, it's messy as usual. Long story short the simplest way is to
use the perl program HEAD or GET in /usr/bin or /usr/local/bin. When
one of the networking module is installed, perl contaminate your bin
dirs with these programs. In the unix shell, try
GET 'http://yahoo.com/'
should do the job. HEAD is similar for http
head. (assuming they are installed.)
if you need more complexty, perl has LWP::Simple and LWP::UserAgent to
begin with. (there are a host of spaghetti others) Both of these needs
to be installed extra. Perhaps consult your sys admin. The last time i
used them was some 2 years ago, so the following code is untested, but
should be it. I don't recall which one can't do what. Your milage may
vary.
use strict;
# use LWP::Simple;
use LWP::UserAgent;
my $ua =3D new LWP::UserAgent;
$ua->timeout(120);
my $url=3D'http://yahoo.com/';
my $request =3D new HTTP::Request('GET', $url);
my $response =3D $ua->request($request);
my $content =3D $response->content();
print $content;
__END__
# note the above perl code. In many perl codes, they sport the Object
Oriented syntax, often concomitantly with a normal syntax version as
well.
----------------
this post is from the perl-python a-day mailing list. Please see
http://xahlee.org/perl-python/python.html
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
------------------------------
Date: 4 Feb 2005 10:02:42 -0800
From: "evillen@innocent.com" <evillen@innocent.com>
Subject: Array reference not consistently interpolating
Message-Id: <1107540162.829506.302140@z14g2000cwz.googlegroups.com>
Hi
I am trying to pass an array reference to a subroutine but get the
error:
"Not an ARRAY reference at array_ref_test.txt line 14."
I have slimmed down my code so don't worry about why I'm using an array
reference. The reference is getting correctly interpolated at some
point as line 12 reports:
"$key is: CONN_UMP_3MM_SMT"
Thanks for any ideas!
Len
## Please remove line numbers!
###########
1 #! perl -w
2 use strict;
4 my (%symbols_and_data, $key);
5 my @symbol_data = ("CONN_UMP_3MM_SMT", "sym.req:0554",
"lib.name:conn_ump_3mm_smt", "height:3.00mm", "used:01ATiss1/Whitney
RF", "rev:2,NJH,26/05/04");
7 &hash_sym(@symbol_data, $key);
9 sub hash_sym{
10 $symbols_and_data{$_[0]} = \@_[0]; #create new Hash key "reference"
11 foreach $key (keys %symbols_and_data){
12 print "\$key is: $key\n"
13 };
14 print "Elements in this hash key are: ".join(', ',
@{$symbols_and_data{$_[0]}})."\n";
15 }
------------------------------
Date: 4 Feb 2005 18:29:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Array reference not consistently interpolating
Message-Id: <Xns95F389484C368asu1cornelledu@132.236.56.8>
"evillen@innocent.com" <evillen@innocent.com> wrote in
news:1107540162.829506.302140@z14g2000cwz.googlegroups.com:
> Hi
>
> I am trying to pass an array reference to a subroutine but get the
> error:
>
> "Not an ARRAY reference at array_ref_test.txt line 14."
>
> I have slimmed down my code so don't worry about why I'm using an
> array reference. The reference is getting correctly interpolated at
> some point as line 12 reports:
>
> "$key is: CONN_UMP_3MM_SMT"
>
> Thanks for any ideas!
> Len
>
> ## Please remove line numbers!
Yeah, thanks ... And with an exclamation point at the end. There is no
point in posting line numbers. It makes it harder than necessary to copy
and paste your code in an editor.
If you want to draw our attention to a line, you can put a comment
_above_ it (not in the right margin, because those comments have an
annoying tendency to run off the end of the line).
> ###########
> 1 #! perl -w
use warnings;
is better because it allows you to selectively disable warnings.
> 2 use strict;
>
> 4 my (%symbols_and_data, $key);
Always declare your vairables in the smallest applicable scope. What is
$key doing here? What is %symbols_and_data doing here? You only use them
in the body of the sub.
> 5 my @symbol_data = ("CONN_UMP_3MM_SMT", "sym.req:0554",
> "lib.name:conn_ump_3mm_smt", "height:3.00mm", "used:01ATiss1/Whitney
> RF", "rev:2,NJH,26/05/04");
Properly formatting your code would give you an advantage when you are
asking for others' help. It is like saying "I respect your time". Not
properly formatting your code is then tantamount to spitting in the faces
of the people whose help you are asking. Just thought I would point that
out.
> 7 &hash_sym(@symbol_data, $key);
>
> 9 sub hash_sym{
> 10 $symbols_and_data{$_[0]} = \@_[0]; #create new Hash key
> "reference" 11 foreach $key (keys %symbols_and_data){
See what I meen by comments wrapping?
I do not know what 'create new Hash Key "reference"' means. It seems like
what you are trying to do is to insert a key into %symbols_and_data hash
whose value is a reference to a hash formed using the elements of
@symbol_data. I have come up with something based on that interpretation.
> 12 print "\$key is: $key\n"
> 13 };
> 14 print "Elements in this hash key are: ".join(', ',
> @{$symbols_and_data{$_[0]}})."\n";
I am speechless in the face of this join call. Is there any reason why
you don't use Data::Dumper?
C:\Documents> cat s__t.pl
#! perl
use strict;
use warnings;
use Data::Dumper;
my @symbol_data = (
'CONN_UMP_3MM_SMT',
'sym.req:0554',
'lib.name:conn_ump_3mm_smt',
'height:3.00mm',
'used:01ATiss1/WhitneyRF',
'rev:2,NJH,26/05/04',
);
my %symbols_and_data;
print Dumper hash_sym(\%symbols_and_data, @symbol_data);
sub hash_sym {
my $h = shift;
$h->{$_[0]} = { @_ };
}
__END__
C:\Documents> perl s__t.pl
$VAR1 = {
'used:01ATiss1/WhitneyRF' => 'rev:2,NJH,26/05/04',
'CONN_UMP_3MM_SMT' => 'sym.req:0554',
'lib.name:conn_ump_3mm_smt' => 'height:3.00mm'
};
Sinan
------------------------------
Date: Fri, 04 Feb 2005 19:32:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Array reference not consistently interpolating
Message-Id: <36htskF4uuqqqU1@individual.net>
evillen@innocent.com wrote:
> I am trying to pass an array reference to a subroutine but get the
> error:
>
> "Not an ARRAY reference at array_ref_test.txt line 14."
You did not pass any array reference, to start with.
> ## Please remove line numbers!
Please don't include line numbers!
Is this what you are trying to do:
my %symbols_and_data;
hash_sym( \@symbol_data );
sub hash_sym {
$symbols_and_data{ shift @{ $_[0] } } = $_[0];
foreach my $key ( keys %symbols_and_data ) {
print "\$key is: $key\n";
print "Elements in this hash key are: " .
join( ', ', @{ $symbols_and_data{$key} } ) . "\n";
};
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 4 Feb 2005 17:32:38 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Equality of hashref objects
Message-Id: <cu0bjm$5es$1@reader2.panix.com>
I have a class that is implemented as a hashref, and furthermore,
the values for the corresponding hash are always scalars. I want
a sub to test for equality between any two instances of this class,
defined roughly as "two instances $x and $y are equal if $x->{
$field } and $y->{ $field } are equal for all instance fields
$field". I took a crack at this function, but it is so *ugly* that
I'm sure there must be a better way. I give my version below for
your mocking pleasure. Any pointers to a better implementation
would be much appreciated.
bill
# ...
BEGIN { # private subs
$_equals = sub {
my @args = @_[0, 1];
for my $field (@_fields) { # @_fields is defined earlier
my @vals = map $_->$field, @args;
my $n_defined = grep defined $_, @vals;
next if $n_defined == 0;
return 0 if $n_defined == 1;
if (2 == grep $_is_numeric($_), @vals) {
return 0 unless $vals[0] == $vals[1];
}
else {
return 0 unless $vals[0] eq $vals[1];
}
}
return 1;
};
$_is_numeric = sub {
# cribbed from a clpm post by Anno Siegel
use warnings 'all', FATAL => 'numeric';
return defined eval { $_[0] == 0 };
};
}
use overload '==' => $_equals, fallback => 1;
# ...
------------------------------
Date: 4 Feb 2005 09:42:41 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Equality of hashref objects
Message-Id: <1107538961.611241.187130@f14g2000cwb.googlegroups.com>
bill wrote:
> I have a class that is implemented as a hashref, and furthermore,
> the values for the corresponding hash are always scalars. I want
> a sub to test for equality between any two instances of this class,
> defined roughly as "two instances $x and $y are equal if $x->{
> $field } and $y->{ $field } are equal for all instance fields
> $field".
If you have two hash references (say, $hashRef1 and $hashRef2), you
might be able to pull it off this way:
use Data::Dumper; # standard module; you should have it
print "Equal\n" if Dumper($hashRef1) eq Dumper($hashRef2);
I'm not positive that Dumper will return all the entries in the same
order for two equivalent hashes, so this MIGHT not work.
However, it still might be worth a shot. Try it out and see what you
get.
I hope this helps.
-- Jean-Luc
------------------------------
Date: Fri, 4 Feb 2005 10:09:20 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Equality of hashref objects
Message-Id: <Pine.GSO.4.21.0502041005470.26230-100000@mtwhitney.nsc.com>
On Fri, 4 Feb 2005, bill wrote:
> I have a class that is implemented as a hashref, and furthermore,
> the values for the corresponding hash are always scalars. I want
> a sub to test for equality between any two instances of this class,
> defined roughly as "two instances $x and $y are equal if $x->{
> $field } and $y->{ $field } are equal for all instance fields
> $field". I took a crack at this function, but it is so *ugly* that
> I'm sure there must be a better way. I give my version below for
> your mocking pleasure. Any pointers to a better implementation
> would be much appreciated.
>
> bill
[ snipped ]
Look at the is_deeply function in Test::More,
or the functions from Test::Deep on CPAN. See
if they offer what you need.
--
Hope this helps,
Steven
------------------------------
Date: 4 Feb 2005 11:03:31 -0800
From: "nobull@mail.com" <nobull@mail.com>
Subject: Re: Equality of hashref objects
Message-Id: <1107543811.374991.63530@l41g2000cwc.googlegroups.com>
bill wrote:
> I have a class that is implemented as a hashref, and furthermore,
> the values for the corresponding hash are always scalars. I want
> a sub to test for equality between any two instances of this class,
> defined roughly as "two instances $x and $y are equal if $x->{
> $field } and $y->{ $field } are equal for all instance fields
> $field". I took a crack at this function, but it is so *ugly* that
> I'm sure there must be a better way. I give my version below for
> your mocking pleasure. Any pointers to a better implementation
> would be much appreciated.
Data::Compare
> if (2 == grep $_is_numeric($_), @vals) {
> return 0 unless $vals[0] == $vals[1];
> }
> else {
> return 0 unless $vals[0] eq $vals[1];
> }
> $_is_numeric = sub {
> use warnings 'all', FATAL => 'numeric';
> return defined eval { $_[0] == 0 };
> };
This has the effect of treating the strings '0' and '0000000000' as the
same. Is that what you wanted? What you you percieve as the problem
if you just use eq all the time?
------------------------------
Date: Fri, 04 Feb 2005 16:41:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Finding disk space used by Windows or Unix directory
Message-Id: <IANMd.8832$Dc.6813@trnddc06>
Joe Smith wrote:
> Jürgen Exner wrote:
>
>> Oh come on, that's a five-liner:
>>
>> use File::Find;
>> my $total;
>> sub wanted {$total += -s;}
>> find (\&wanted, 'c:/tmp');
>> print $total;
>
> That does not return the total disk usage.
> You're assuming that a one-byte file takes up just one
> byte on the disk, when it really takes up an entire
> block (or an entire cluster).
That's true. My suggestion compiles the total file size (by some definition
of file size).
As Anno has pointed out there are many more pitholes in _what_ you want to
calculate when getting into sparse files, special files, hardlinked files,
softlinks, etc.
jue
------------------------------
Date: Fri, 04 Feb 2005 17:45:46 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Finding disk space used by Windows or Unix directory
Message-Id: <36hnigF4di271U1@individual.net>
john_ramsden@sagitta-ps.com wrote:
> For Windows and Unix I need a perl module or script[s] that
> returns the disk space occupied by a specified directory
> (including all files and subdirectories recursively).
>
> I could write one using File::Find or equivalent; but I'd
> rather not reinvent the wheel if there's already a tried
> and tested module or code out there, which having spent
> some fruitless time searching I'm beginning to doubt.
Recently I wrote a CGI script for monitoring disk usage on Linux. I used
the du command, and possibly that's available on Unix as well (but
probably not on Windows).
Anyway, it may give you some ideas:
http://gunnar.cc/cgi-bin/cvsweb.cgi/misc/diskusage.cgi?cvsroot=gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 04 Feb 2005 18:02:44 +0100
From: Rasto Levrinc <rasto@gmx.at>
Subject: Re: Finding disk space used by Windows or Unix directory
Message-Id: <4203a9cf$0$10578$3b214f66@tunews.univie.ac.at>
Joe Smith wrote:
>
> use constant BLOCK => 4096; # May be different on each disk
> sub wanted {$total += int ((BLOCK - 1 + -s) / BLOCK) * BLOCK; }
Why not to use block size and blocks values from stat function?
perldoc -f stat
--
Rasto Levrinc
http://sourceforge.net/projects/rlocate/
------------------------------
Date: 04 Feb 2005 17:59:23 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Google Groups posters, please read
Message-Id: <yzdekfw45xw.fsf@invalid.net>
ioneabu@yahoo.com writes:
> > Recently, this newsgroup has seen a deluge of Google Groups posters
> who
> > apparently don't read or ignore Google Groups's own advice. I would
> > encourage all Usenet regulars who become annoyed at this tendency to
> > refer the offenders to this policy.
> >
> > Thank you for your time,
> > Paul Lalli
>
> I find it hard to believe that Google, being a company whose only
> products are software, and it's main piece of software a web based
> search engine, has not leveraged the power of Perl in some way. If
> that is the case, you would think that someone with some influence
> there has read postings from c.l.p.m and would have addressed the
> problem of mangled code and maybe even responded officially or even
> anonymously to why the interface is not Perl-friendly. Then again,
> maybe they have. Maybe some regular posters here work for or have
> worked for Google.
>
> What is the best alternative as far as news reading software? I have
> not yet used any that I am as happy with as Google as far as keeping up
> with old threads and relevant threads.
>
> I tried a current version of rn but found it to be a little complex,
> like learning vi from scratch.
I use 'gnus' in Emacs.
------------------------------
Date: Fri, 04 Feb 2005 17:18:08 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: PAR/PP on Windows XP with ActiveState
Message-Id: <3hb7015nprprj964fjfvcbdu0dq9vapi38@4ax.com>
sigzero@gmail.com wrote:
>I am trying to get my company to get me the Pro Pack or the Dev kit.
>Other than that I have to rely on "free".
You could take a look at TinyPerl, too.
<http://tinyperl.sourceforge.net/>
--
Bart.
------------------------------
Date: Fri, 04 Feb 2005 17:15:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex: Selectively choose result group?
Message-Id: <36hlq0F51upotU1@individual.net>
Prab_kar@hotmail.com wrote:
> Thanks a lot, Gunnar.
> It works like a charm.
>
> Now, I'll spend my weekend trying to figure _why_ it works :).
Good.
The reference docs
perldoc perlre
should then be your best friend. Also
perldoc perlretut
may be useful.
Feel free to come back here if there is something you fail to figure out.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 4 Feb 2005 17:02:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regex: Selectively choose result group?
Message-Id: <cu09qe$mea$1@mamenchi.zrz.TU-Berlin.DE>
<Prab_kar@hotmail.com> wrote in comp.lang.perl.misc:
Please give an attribution and some context with your reply.
> "...insist in using a single regex..."
> Well, I've to confess, this is not strictly perl-related.
> I've to implement this regex solution in an xml file and it has to be
> in a single regex.
So I spent my time working out a solution that you can't use because
you didn't tell us the whole story. Care to imagine how that sits with
me?
Anno
------------------------------
Date: Fri, 04 Feb 2005 18:19:09 +0100
From: Rasto Levrinc <rasto@gmx.at>
Subject: Re: Regex: Selectively choose result group?
Message-Id: <4203ada7$0$10578$3b214f66@tunews.univie.ac.at>
Gunnar Hjalmarsson wrote:
> Prab_kar@hotmail.com wrote:
>
>> I wonder if this can be done through regex matching.
>>
>> I have a string of unix path, which can be either
>> /home/MyAccount/Proj/SubProj or
>> /home/MyAccount/Proj
>>
>>> From this I want to find
>>
>> 1. the "Proj" and "SubProj" portion, when the string has a SubProj
>>
>> 2. Just the "Proj" protion if there are no SubProjs.
>>
>> I tried,
>> -------------------------------------
>> #!/usr/local/bin/perl -w
>>
>> use strict ;
>> my $string = '/home/MyAccount/Proj/SubProj' ;
>> # my $string = '/home/MyAccount/Proj' ;
>>
>> if ( $string =~ m/(.*)\/(.*)\/(.*)$/ )
>> {
>> print "Project: $2 \t SubProject: $3\n" ;
>> }
>> -------------------------------------
>>
>> It works fine when the string has Proj and SubProj but, when I
>> uncomment the later definition of string, I get MyAccount as my
>> project. Is there a way I can choose Project to $2 or $3 based on the
>> string?
>>
>> Or, maybe I'm thinking of a wrong solution.
>
>
> Try this:
>
> if ( $string =~ m#/MyAccount/([^/]+)(?:/(.+))?# ) {
> print "Project: $1" . ($2 ? "\tSubProject: $2" : '') . "\n" ;
> }
>
same thing, but shorter...
if ( $string =~ m#/MyAccount/([^/]+)/?(.*)# ) {
print "Project: $1" . ($2 ? "\tSubProject: $2" : '') . "\n" ;
}
--
Rasto Levrinc
http://sourceforge.net/projects/rlocate/
------------------------------
Date: Fri, 04 Feb 2005 17:32:57 +0100
From: Rasto Levrinc <rasto@gmx.at>
Subject: Re: Regular expression woes
Message-Id: <4203a2d4$0$8024$3b214f66@tunews.univie.ac.at>
Mark (News) wrote:
> I appreciate all the effort in providing a solution to the wider
> problem, but perhaps I should have been more explicit - my fault.
>
> I'm specifically trying to avoid using the host shell to do the
> negation even though I can use this approach in just about any
> language. What I'm really after is to contain the logic entirely within
> the regular expression.
You can do it with a zero-width negative look-ahead assertion in perl.
$string=~/^(?!http)/
--
Rasto Levrinc
http://sourceforge.net/projects/rlocate/
------------------------------
Date: 4 Feb 2005 08:48:17 -0800
From: "Mark (News)" <news@mail.adsl4less.com>
Subject: Re: Regular expression woes
Message-Id: <1107535697.798991.31720@o13g2000cwo.googlegroups.com>
Wow - quite brilliant!
Clearly this was far too easy for you. :-)
Cheers
Mark
------------------------------
Date: Fri, 4 Feb 2005 18:05:01 +0100
From: "Dietmar Meier" <usereplytoinstead@innoline-systemtechnik.de>
Subject: Re: Regular expression woes
Message-Id: <36hoasF52jhqlU1@individual.net>
Rasto Levrinc wrote:
>> What I'm really after is to contain the logic entirely within
>> the regular expression.
> You can do it with a zero-width negative look-ahead assertion in perl.
>
> $string=~/^(?!http)/
Some JavaScript implementations implement regular expressions but
don't implement look-ahead assertions. Here you would need
/^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)
ciao, dhgm
------------------------------
Date: 04 Feb 2005 17:53:11 GMT
From: "Evertjan." <exjxw.hannivoort@interxnl.net>
Subject: Re: Regular expression woes
Message-Id: <Xns95F3C02282D3Beejj99@194.109.133.29>
Dietmar Meier wrote on 04 feb 2005 in comp.lang.javascript:
>>> What I'm really after is to contain the logic entirely within
>>> the regular expression.
>
>> You can do it with a zero-width negative look-ahead assertion in perl.
>>
>> $string=~/^(?!http)/
>
> Some JavaScript implementations implement regular expressions but
> don't implement look-ahead assertions. Here you would need
>
> /^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)
[The $ cannot be right, I think.]
r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p]))/.test(s)
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
------------------------------
Date: Fri, 4 Feb 2005 19:09:47 +0100
From: "Dietmar Meier" <usereplytoinstead@innoline-systemtechnik.de>
Subject: Re: Regular expression woes
Message-Id: <36hs4bF50p87sU1@individual.net>
Evertjan. wrote:
>> /^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)
> [The $ cannot be right, I think.]
For what value of string do you think, the "$" would lead to the
wrong result?
> r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p]))/.test(s)
This would not match strings with 3 or less characters.
ciao, dhgm
------------------------------
Date: 04 Feb 2005 18:27:26 GMT
From: "Evertjan." <exjxw.hannivoort@interxnl.net>
Subject: Re: Regular expression woes
Message-Id: <Xns95F3C5F131A46eejj99@194.109.133.29>
Dietmar Meier wrote on 04 feb 2005 in comp.lang.javascript:
> Evertjan. wrote:
>
>>> /^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)
>
>> [The $ cannot be right, I think.]
>
> For what value of string do you think, the "$" would lead to the
> wrong result?
"xttp://" should return true
"http://" should return false
Yes, you are right here.
>> r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p]))/.test(s)
>
> This would not match strings with 3 or less characters.
Yes, you are right again.
Let me try:
r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p])|(.{0,3}$))/.test(s)
[I could loose some () but I like them for clarity
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
------------------------------
Date: 04 Feb 2005 18:31:50 GMT
From: xhoster@gmail.com
Subject: Re: Socket programming blunders....
Message-Id: <20050204133150.187$Ee@newsreader.com>
"gdh" <gdh@acentral.co.uk> wrote:
> Thanks for the responses :)
>
> I think I decided on using the fork() examples from the Cookbook
> because at every moment, the client may need to send, OR the PBX may
> have something to say to me, so I don't want to block at any time.
Yeah, if both ends of the connection can iniate reqeusts (as opposed to
one end just responding to requests made by the other), that makes
things a lot more difficult.
> I
> also could understand the forking better than I could select() :)
Alas, by the time you add the IPC to the forking, that will no longer
be the case. :)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 4 Feb 2005 10:14:19 -0800
From: ai2003lian@yahoo.com
Subject: why the variable become local?
Message-Id: <1107540859.281482.203830@l41g2000cwc.googlegroups.com>
I'm new with perl. Sorry if this question is too naive. I have the
follwing piece of code, and I don't know why the variable $login apear
local:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/usr/local/bin/perl
package downlaod;
use Net::FTP;
use vars qw($ftp_server, $login, $password);
# Some settings
$idx = 0;
$next_arg = $ARGV[idx];
if(!$next_arg){
printUsage();
exit;
}
while($next_arg){
if($next_arg == "-h"){
$ftp_server=$ARGV[++$idx]; #the host name of the ftp
server
if (!$ftp_server){
printUsage();
exit;
}
print "$ftp_server \n";
}elsif($next_arg == "-u"){
$login=$ARGV[++$idx]; #user name
if (!$login){
printUsage();
exit;
}
print "$login \n";
}elsif($next_arg == "-p"){
$password=$ARGV[++$idx];
if(!$password ){
printUsage();
exit;
}
print "$password\n";
}
$next_arg = $ARGV[++$idx];
}
print "login= $login \n"; #problem here
sub printUsage(){
print "\aUsage: downlaod_zip_file -h <ftp server> -u <user
name> -p password \n";
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
when I try to print $login after the while loop, $login is empty! Why
is that? Please help!
Thanks in advance.
------------------------------
Date: 4 Feb 2005 10:34:17 -0800
From: "Matt" <msporleder@gmail.com>
Subject: Re: why the variable become local?
Message-Id: <1107542057.779581.96700@z14g2000cwz.googlegroups.com>
use Getopt::Std;
Get you command line options this way.
ai2003lian@yahoo.com wrote:
> I'm new with perl. Sorry if this question is too naive. I have the
> follwing piece of code, and I don't know why the variable $login
apear
> local:
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> #!/usr/local/bin/perl
> package downlaod;
>
> use Net::FTP;
> use vars qw($ftp_server, $login, $password);
>
> # Some settings
>
> $idx = 0;
> $next_arg = $ARGV[idx];
> if(!$next_arg){
> printUsage();
> exit;
> }
>
> while($next_arg){
> if($next_arg == "-h"){
> $ftp_server=$ARGV[++$idx]; #the host name of the ftp
> server
> if (!$ftp_server){
> printUsage();
> exit;
> }
> print "$ftp_server \n";
> }elsif($next_arg == "-u"){
> $login=$ARGV[++$idx]; #user name
> if (!$login){
> printUsage();
> exit;
> }
> print "$login \n";
> }elsif($next_arg == "-p"){
> $password=$ARGV[++$idx];
> if(!$password ){
> printUsage();
> exit;
> }
> print "$password\n";
> }
> $next_arg = $ARGV[++$idx];
> }
>
> print "login= $login \n"; #problem here
>
> sub printUsage(){
> print "\aUsage: downlaod_zip_file -h <ftp server> -u <user
> name> -p password \n";
> }
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> when I try to print $login after the while loop, $login is empty! Why
> is that? Please help!
>
> Thanks in advance.
------------------------------
Date: 4 Feb 2005 18:35:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why the variable become local?
Message-Id: <Xns95F38A5581687asu1cornelledu@132.236.56.8>
ai2003lian@yahoo.com wrote in news:1107540859.281482.203830
@l41g2000cwc.googlegroups.com:
> I'm new with perl. Sorry if this question is too naive.
You should take the time to read the posting guidelines for
comp.lang.perl.misc and follow the advice given there.
> follwing piece of code, and I don't know why the variable $login apear
> local:
I don't know what it means for a variable to appear local.
> #!/usr/local/bin/perl
> package downlaod;
Is that a typo?
>
> use Net::FTP;
> use vars qw($ftp_server, $login, $password);
Now, these are other typos.
If you had asked perl, it would have told you:
Possible attempt to separate words with commas at s__t.pl line 9.
'$ftp_server,' is not a valid variable name under strict vars at s__t.pl
line 9
BEGIN failed--compilation aborted at s__t.pl line 9.
where line 9 refers the use vars statement.
You should always have
use strict;
use warnings;
at the beginning of your script. In case you prefer to live without those
two, then you should not post your code here.
So, add those to your script, get rid of the globals, then post here if
you encounter any problems.
Sinan.
------------------------------
Date: 4 Feb 2005 18:42:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why the variable become local?
Message-Id: <Xns95F38B5EB1B44asu1cornelledu@132.236.56.8>
"Matt" <msporleder@gmail.com> wrote in news:1107542057.779581.96700
@z14g2000cwz.googlegroups.com:
[ Please take the time to read the posting guidelines for this group.
Please do not top-post. See also <URL: http://tinyurl.com/6z7k2>
]
> use Getopt::Std;
>
> Get you command line options this way.
How does that show the OP what he is doing wrong? Did you really have to
quote his whole script without responding to any specific part of it?
Sinan
------------------------------
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 V10 Issue 7737
***************************************