[16257] in Perl-Users-Digest
Perl-Users Digest, Issue: 3669 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 14 14:10:45 2000
Date: Fri, 14 Jul 2000 11:10:33 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963598231-v9-i3669@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 14 Jul 2000 Volume: 9 Number: 3669
Today's topics:
Is there a better way (Multi-dimen. Arrays) <fortinj@attglobal.net>
Re: Is there a better way (Multi-dimen. Arrays) <rhomberg@ife.ee.ethz.ch>
Re: Is there a better way (Multi-dimen. Arrays) nobull@mail.com
Re: Is there a better way (Multi-dimen. Arrays) <fortinj@attglobal.net>
Re: Is there a better way (Multi-dimen. Arrays) <fortinj@attglobal.net>
limited control over the file pointer tnr_prabhu@my-deja.com
Re: limited control over the file pointer <rhomberg@ife.ee.ethz.ch>
Re: limited control over the file pointer nobull@mail.com
Re: local and use strict nobull@mail.com
Re: local and use strict <bcaligari@shipreg.com>
Re: Modules/scripts for EDI processing <lars@thegler.dk>
Re: multiline reqexp question <vibrato@my-deja.com>
Re: multiline reqexp question <arthur.haas@westgeo.com>
Net/Config.pm problem <slavelle@concentus-tech.com>
Re: Net::FTP error:Bad arg length for Socket::unpack_so <rhomberg@ife.ee.ethz.ch>
NEt::POP3 difficulties <someone@msn.com>
Re: Newbie: Reading in file contents (Tony Balazs)
Re: Newbie: Reading in file contents prakash_ojha@my-deja.com
Parameter passing squidrocks@my-deja.com
Re: Parameter passing nobull@mail.com
Re: Perl Expert? I need help! <cal@iamcal.com>
Re: Perl Expert? I need help! <rhomberg@ife.ee.ethz.ch>
Re: Perl Expert? I need help! <bart.lateur@skynet.be>
Re: Perl Expert? I need help! nobull@mail.com
Re: Perl Expert? I need help! (Tad McClellan)
Re: perl prog to change UNIX password through CGI spock0000@my-deja.com
PerlScript on Win2K danno6000@hotmail.com
PerlScript on Win2K danno6000@my-deja.com
POP3 password <propman@noemail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 14 Jul 2000 11:17:35 -0400
From: John Fortin <fortinj@attglobal.net>
Subject: Is there a better way (Multi-dimen. Arrays)
Message-Id: <396F2F0F.8CD66117@attglobal.net>
Is there a better way to add data to a "multi-dimentional" array than
this... See line marked with <==========
This code works, but this line seems clunky.
Thanks,
John Fortin
sub GetPCSteps {
my @data = @_;
my @steps;
my $stepcounter = 0;
while (@data) {
do {
$data[0] =~
s/\s+$//; # delete trailing
while space
$data[0] =
$data[0]."\n"; # add linefeed
push @{$steps[$stepcounter]}, $data[0]; # add
line to array $steps[$stepcounter] <========== ?
shift
@data; # remove
current $data[0]
} until (!@data || $data[0] =~ /^DATE:/); #
continue until end or beginning of next record
$stepcounter++;
# do next record
}
for (my $x = 0; $x <= $#steps; $x++) { #
for (my $y = 0; $y <= $#{$steps[$x]}; $y++) { # Print
out all records
print
$steps[$x][$y]; #
}
}
}
------------------------------
Date: Fri, 14 Jul 2000 17:49:24 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Is there a better way (Multi-dimen. Arrays)
Message-Id: <396F3684.742ABD21@ife.ee.ethz.ch>
John Fortin wrote:
>
> Is there a better way to add data to a "multi-dimentional" array than
> this... See line marked with <==========
> This code works, but this line seems clunky.
That's the method I use, rather normal. But your indentation and
linewrapping is screwed
- Alex
> $data[0] =~
> s/\s+$//; # delete trailing
> while space
> $data[0] =
> $data[0]."\n"; # add linefeed
> push @{$steps[$stepcounter]}, $data[0]; # add
> line to array $steps[$stepcounter] <========== ?
------------------------------
Date: 14 Jul 2000 17:41:42 +0100
From: nobull@mail.com
Subject: Re: Is there a better way (Multi-dimen. Arrays)
Message-Id: <u9hf9su0jd.fsf@wcl-l.bham.ac.uk>
John Fortin <fortinj@attglobal.net> writes:
> Is there a better way to add data to a "multi-dimentional" array than
> this... See line marked with <==========
Give the stuff surrounding it no it is the best way to do what you are doing.
> This code works, but this line seems clunky.
No, actually it is the code either side that's clunky.
Of course the clunkiest thing about your script is the formatting
which makes it almost impossible to reaf.
I've fixed that below.
> sub GetPCSteps {
>
> my @data = @_;
> my @steps;
> my $stepcounter = 0;
>
> while (@data) {
> do {
> $data[0] =~ s/\s+$//;
> $data[0] = $data[0]."\n";
> push @{$steps[$stepcounter]}, $data[0];
> shift @data;
> } until (!@data || $data[0] =~ /^DATE:/);
> $stepcounter++;
> }
>
> for (my $x = 0; $x <= $#steps; $x++) {
> for (my $y = 0; $y <= $#{$steps[$x]}; $y++) {
> print $steps[$x][$y];
> }
> }
> }
There are lots of ways to do it but I would do:
sub GetPCSteps {
my @steps;
local $_;
while (@_) {
my @row;
while (@_) {
$_ = shift;
last if /^DATE:/;
s/\s*$/\n/;
push @row, $_;
}
push @steps, \@row;
}
print @$_ for @steps;
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 14 Jul 2000 13:22:07 -0400
From: John Fortin <fortinj@attglobal.net>
Subject: Re: Is there a better way (Multi-dimen. Arrays)
Message-Id: <396F4C3F.38025A23@attglobal.net>
nobull@mail.com wrote:
>
> John Fortin <fortinj@attglobal.net> writes:
>
> > Is there a better way to add data to a "multi-dimentional" array than
> > this... See line marked with <==========
>
> Give the stuff surrounding it no it is the best way to do what you are doing.
>
> > This code works, but this line seems clunky.
>
> No, actually it is the code either side that's clunky.
Beauty is in the eye of the beholder :) To be honest, your solution is
the better perl solution, but I find it harder to read.
>
> Of course the clunkiest thing about your script is the formatting
> which makes it almost impossible to reaf.
I don't know what happened. It was fine when I sent it. Maybe the
Netscape mail client screwed it up.
>
> I've fixed that below.
>
> > sub GetPCSteps {
> >
> > my @data = @_;
> > my @steps;
> > my $stepcounter = 0;
> >
> > while (@data) {
> > do {
> > $data[0] =~ s/\s+$//;
> > $data[0] = $data[0]."\n";
realized that this is better after I sent post: $data[0] =~ s/\s+$/\n/;
> > push @{$steps[$stepcounter]}, $data[0];
> > shift @data;
> > } until (!@data || $data[0] =~ /^DATE:/);
> > $stepcounter++;
> > }
> >
> > for (my $x = 0; $x <= $#steps; $x++) {
> > for (my $y = 0; $y <= $#{$steps[$x]}; $y++) {
> > print $steps[$x][$y];
> > }
Here I really wanted to iterate the array one by one in this manner.
> > }
> > }
>
> There are lots of ways to do it but I would do:
>
> sub GetPCSteps {
> my @steps;
> local $_;
>
> while (@_) {
> my @row;
> while (@_) {
> $_ = shift;
> last if /^DATE:/;
> s/\s*$/\n/;
> push @row, $_;
> }
> push @steps, \@row;
> }
>
> print @$_ for @steps;
Thanks for the input :)
John
------------------------------
Date: Fri, 14 Jul 2000 13:23:53 -0400
From: John Fortin <fortinj@attglobal.net>
Subject: Re: Is there a better way (Multi-dimen. Arrays)
Message-Id: <396F4CA9.21679B30@attglobal.net>
Alex Rhomberg wrote:
>
> John Fortin wrote:
> >
> > Is there a better way to add data to a "multi-dimentional" array than
> > this... See line marked with <==========
> > This code works, but this line seems clunky.
>
> That's the method I use, rather normal. But your indentation and
> linewrapping is screwed
>
I don't know what happened. It was fine when I sent it. Maybe the
Netscape mail client screwed it up.
Sorry,
John Fortin
------------------------------
Date: Fri, 14 Jul 2000 15:09:14 GMT
From: tnr_prabhu@my-deja.com
Subject: limited control over the file pointer
Message-Id: <8knae9$fsu$1@nnrp1.deja.com>
Hi subscribers:
I am new to PERL and would like to know if there is any way
through which I can use the language to recognise a regular expression
and then store the contents of an entire line which is physically 3
lines above where the regular expression was recognised? The number 3
is just an example. I know it would be very memory intensive but at the
user's risk would it be possible to command PERL to remember the
contents of a line which is X lines above or below where the pattern
match was found?
Thanks a lot in advance,
Prabhu
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 14 Jul 2000 17:44:09 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: limited control over the file pointer
Message-Id: <396F3549.388B58D9@ife.ee.ethz.ch>
tnr_prabhu@my-deja.com wrote:
>
> Hi subscribers:
> I am new to PERL and would like to know if there is any way
> through which I can use the language to recognise a regular expression
> and then store the contents of an entire line which is physically 3
> lines above where the regular expression was recognised? The number 3
> is just an example.
Don't know about PERL, but Perl can do that. And so can grep (1).
Some month ago, there was a golf contest on this ng to emulate the
behaviour of grep. It should still be on deja news.
- Alex
------------------------------
Date: 14 Jul 2000 17:13:59 +0100
From: nobull@mail.com
Subject: Re: limited control over the file pointer
Message-Id: <u9lmz4u1tk.fsf@wcl-l.bham.ac.uk>
tnr_prabhu@my-deja.com writes:
> Hi subscribers:
> I am new to PERL and would like to know if there is any way
> through which I can use the language to recognise a regular expression
> and then store the contents of an entire line which is physically 3
> lines above where the regular expression was recognised? The number 3
> is just an example. I know it would be very memory intensive but at the
> user's risk would it be possible to command PERL to remember the
> contents of a line which is X lines above or below where the pattern
> match was found?
Perl is a general purpose programming language. Just write a program
to do this like you would in any language. You want a FIFO queue to
hold the last X lines of the file. The push() and shift() functions
can be used to implement a FIFO structure.
#!/usr/bin/perl -w
use strict;
my $X = 3;
my @fifo;
$#fifo = $X - 1 ; # An array of $X undefined elements
while(<>) {
push @fifo, $_;
my $X_lines_ago = shift @fifo;
print $X_lines_ago if /pattern/;
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 14 Jul 2000 17:25:58 +0100
From: nobull@mail.com
Subject: Re: local and use strict
Message-Id: <u9itu8u19l.fsf@wcl-l.bham.ac.uk>
"Brendon Caligari" <bcaligari@shipreg.com> writes:
> Trying to figure out how to make correct use of 'local' variables using
> 'strict'
Correct use of local is as little as possible. Usually it should only
be used to localise changes to "special" variables (which, of course
don;t need to be declared).
> Am i on the right track?
[ snip code demonstating good understanding ]
Yes. You seem to understand how "use vars" and "local" work.
However, in general you should avoid doing this. local() is a powerfull
tool in the cases where it is the right tool. It is however not often
the right tool.
> is it good practice to 'localise' $_ , etc?
Yes, this is about the only thing you should usually use local() for
in most scripts.
Note that "for", "map" and "grep" implicity localise $_, you don't
need to do it explicitly.
This can lead to complacancy and "while(<FILE>)" does _not_ implicity
localise $_.
Any subroutine that uses the "while(<FILE>)" construct should localise
$_.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 14 Jul 2000 19:46:13 +0200
From: "Brendon Caligari" <bcaligari@shipreg.com>
Subject: Re: local and use strict
Message-Id: <8knj1j$pv3$1@news.news-service.com>
<nobull@mail.com> wrote in message news:u9itu8u19l.fsf@wcl-l.bham.ac.uk...
> However, in general you should avoid doing this. local() is a powerfull
> tool in the cases where it is the right tool. It is however not often
> the right tool.
I admit that while I appreciate it's existence, I couldn't really conceive
any particular use for it. I classify it together with taboos like 'gotos'.
I'm still trying to 'accept' previousy frowned upon concepts such
as breaking straight out of a number of nested loops
>
> > is it good practice to 'localise' $_ , etc?
>
> Yes, this is about the only thing you should usually use local() for
> in most scripts.
fair enough :)
>
> Note that "for", "map" and "grep" implicity localise $_, you don't
> need to do it explicitly.
Aha. So, really and truly it's irrelevant what gets passed to, say,
a foreach iteration in fact being 'localised'.
#!/usr/bin/perl -w
use strict;
my( $s );
$s = "Whatever";
print("Entry Value = $s\n");
foreach $s (1..5) { print("Interim Value = $s\n"); }
print("Exit Value = $s\n");
exit(0);
..yeah...in fact it gave "Whatever 1 2 3 4 5 Whatever"
>
> This can lead to complacancy and "while(<FILE>)" does _not_ implicity
> localise $_.
>
> Any subroutine that uses the "while(<FILE>)" construct should localise
> $_.
hmm...was unsure of that too...thanks :)
Thanks for the help...I really appreciated it
Brendon
++++
------------------------------
Date: Fri, 14 Jul 2000 17:52:47 +0200
From: Lars Thegler <lars@thegler.dk>
Subject: Re: Modules/scripts for EDI processing
Message-Id: <396F374F.4EE7E4FB@thegler.dk>
Roger Tubby wrote:
>
> It seems unbelievable that I cannot locate any modules or scripts that
> handle EDI messages. I am specifically looking for the capability to read
> ANSI X12 headers (ISA's), catalogs (832), and other message formats.
>
> I am aware of the XML/EDI work ongoing (XML-Edifact) and plan to convert to
> XML over time.
EDI message parsing is neither an easy, nor a straightforward task, if
done in a general, extensible way. If you want to parse only a single,
or a few different message formats, your best bet is probably to grab
XML::Edifact, and extend the EDI parsing code to do your thing. If you
want to handle many different message formats, then look at a commercial
Edifact converter.
Kind regards,
Lars Thegler
------------------------------
Date: Fri, 14 Jul 2000 15:55:56 GMT
From: Lance Hoffmeyer <vibrato@my-deja.com>
Subject: Re: multiline reqexp question
Message-Id: <8knd62$i0r$1@nnrp1.deja.com>
Using 'while' was exactly what I was doing! I am still having problems
though. I am trying the /../ approach but I am still doing something
wrong (probably in opening the file).. Here is my entire code this time:
# Get a list of files to process
@listofdat = glob("*.asc");
# work on each file
foreach $listt (@listofdat){
print "$listt \n";
#open(IN, "<$listt>");
while(<$llist>){
print unless /^MACRO/../^ENDMACRO/;
#close(IN);
}
}
Any help would be appriciated.
Lance
> Hi Lance,
>
> Lance Hoffmeyer <vibrato@my-deja.com> writes:
>
> > s/MACRO.*ENDMACRO//s
> >
> > does not work.
>
> Well, this works for me:
>
> #!/usr/bin/perl -w
> use strict;
>
> # Slurp _entire file_ into one scalar
> $_ = do {local $/; <DATA>};
>
> # Delete _first_ occurance of MACRO ... ENDMACRO
> s/MACRO.*ENDMACRO//s;
>
> # Output is
> # blabla
> #
> # blabla
> print;
>
> __DATA__
> blabla
> MACRO
> text
> text
> text
> ENDMACRO
> blabla
>
> > What am I missing here? What would make this work?
>
> The problem is probably in the part of your program that you don't
> show us. If you read your file line by line, like in
>
> while (<DATA>) {
> s/MACRO.*ENDMACRO//s;
> print;
> }
>
> you apply the substitution to every line individually - but there is
> no line which contains both 'MACRO' and 'ENDMACRO'.
>
> You could apply the substitution to the whole file in one go as I did
> in the example above, but then you probably want to use the /g
> modifier on your regexp to kill _all_ occurrences of your pattern. The
> other solution is processing the file line by line, but using the '..'
> operator from perlop:
>
> #!/usr/bin/perl -w
> use strict;
>
> while (<DATA>) {
> print unless /^MACRO/../^ENDMACRO/;
> }
>
> __DATA__
> blabla
> MACRO
> text
> text
> text
> ENDMACRO
> blabla
>
> or shorter
>
> perl -ne 'print unless /^MACRO/../^ENDMACRO/'
>
> HTH
>
> Best,
>
> Marc
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 14 Jul 2000 11:23:11 -0500
From: Art Haas <arthur.haas@westgeo.com>
Subject: Re: multiline reqexp question
Message-Id: <lr66q8ptow.fsf@yoda.wg.waii.com>
Lance Hoffmeyer <vibrato@my-deja.com> writes:
> Using 'while' was exactly what I was doing! I am still having problems
> though. I am trying the /../ approach but I am still doing something
> wrong (probably in opening the file).. Here is my entire code this time:
>
> # Get a list of files to process
> @listofdat = glob("*.asc");
>
> # work on each file
> foreach $listt (@listofdat){
> print "$listt \n";
>
> #open(IN, "<$listt>");
>
> while(<$llist>){
> print unless /^MACRO/../^ENDMACRO/;
>
>
> #close(IN);
> }
>
> }
>
The way you're dealing with the files is wrong. I'd also suggest
reading the the documentation on opendir(), readdir(), and closedir()
to avoid glob().
Try something like this ...
$ cat foo.pl
#!/usr/local/bin/perl
use strict;
opendir(PWD,".") || die "Can't open `.'! $!\n";
my @listofdat = grep(/\.asc$/, readdir(PWD));
closedir(PWD);
foreach my $file (@listofdat) {
open(FILE,"<$file") || die "Can't open `$file'! $!\n";
my $printflag = 1;
while(<FILE>) {
$printflag = 0 if (/^MACRO/);
print if ($printflag);
$printflag = 1 if (/^ENDMACRO/);
}
}
$ cat foo.asc
1
2
3
4
5
MACRO
a
b
c
d
e
ENDMACRO
6
7
8
9
$ perl foo.pl
1
2
3
4
5
6
7
8
9
$
Other solutions certainly exist.
--
###############################
# Art Haas
# (713) 689-2417
###############################
------------------------------
Date: Fri, 14 Jul 2000 13:06:36 -0400
From: Sean Lavelle <slavelle@concentus-tech.com>
Subject: Net/Config.pm problem
Message-Id: <396F489B.382CEED3@concentus-tech.com>
Hi,
I am trying to use Activestates perl to do somethings. One of
the things I needed to do was to use Net::FTP. So i went out and
installed libnet.ppd from Activestate. After entering in the
information that Net/Config.pm wanted I tried to run my program (the
only module it uses is Net::FTP). This is what I got:
syntax error at D:/Perl/site/lib/Net/Config.pm line 70, near ">"
Compilation failed in require at D:/Perl/site/lib/Net/FTP.pm line 21.
BEGIN failed--compilation aborted at D:/Perl/site/lib/Net/FTP.pm line
21.
Compilation failed in require at lg_updater.pl line 6.
BEGIN failed--compilation aborted at lg_updater.pl line 6.
This is what the auto generated last bit of config.pm look like:
DATA>%NetConfig = (
ftp_int_passive => '0',
snpp_hosts => [],
inet_domain => 'mydomain.com',
test_exist => '1',
daytime_hosts => [],
ph_hosts => [],
time_hosts => [],
smtp_hosts => [],
ftp_ext_passive => '0',
ftp_firewall => undef,
test_hosts => '0',
nntp_hosts => ['news.mydomain.com'],
pop3_hosts => ['pop.mydomain.com'],
);
1;
I have no idea what's going on. I have even tried to install libnet
without filling in this info and it crashes. If anybody could help I
would really appreciate it.
Sean
slavelle@concentus-tech.com
------------------------------
Date: Fri, 14 Jul 2000 17:18:32 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Net::FTP error:Bad arg length for Socket::unpack_sockaddr_in
Message-Id: <396F2F48.F8348A92@ife.ee.ethz.ch>
Yu Zhang wrote:
>
> Hi folks,
> I wrote a simple script using Net::FTP to download bunch of files,
> each time after processing several hundred of them, the script
> stops and prints
>
> "Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16
> at /usr/lib/perl5/5.00503/i386-linux/Socket.pm line
> 295, <FILE> chunk 1130."
>
> Anyone has an idea what the message means and how to get round of it?
The message means that that the argument to said function is wrong. I'd
fire up the debugger, put a breakpoint at that line and examine the
stack trace to find out why that argument is zero.
- Alex
------------------------------
Date: Fri, 14 Jul 2000 12:21:40 -0500
From: "Somebody Special" <someone@msn.com>
Subject: NEt::POP3 difficulties
Message-Id: <oUHb5.30$wr2.500338@sol.pdnt.net>
I am having some trouble accessing message content with Net::POP3
I can get the correct number of messages with:
my $pop = Net::POP3->new($server);
my $numMsgs = $pop3->login($user,$pass);
But when I try to dereference the result of
my $msgList = $pop3->list();
I cannot access the has table -- the documentation says that this is a
reference to a hash table...
Does anyone know how to effectively use this module? Or can someone please
recommend a better POP3 module than Net::POP3?
Thank you,
Tal Yardeni
------------------------------
Date: Fri, 14 Jul 2000 15:53:53 GMT
From: tbalazs-this-must-go@netcomuk.co.uk (Tony Balazs)
Subject: Re: Newbie: Reading in file contents
Message-Id: <396f377c.13157951@1.0.0.119>
Thanks everyone! Help much appreciated.
Tony.
------------------------------
Date: Fri, 14 Jul 2000 16:20:25 GMT
From: prakash_ojha@my-deja.com
Subject: Re: Newbie: Reading in file contents
Message-Id: <8knejm$jb2$1@nnrp1.deja.com>
try this:
open (JOBS, "jobs.dat");
while($line = <JOBS>)
{ print $line; }
close (JOBS);
> #!/usr/bin/perl
> open (JOBS, "/usr/local/www/dats/jobs.dat");
> $jobs = <JOBS>;
> print $jobs;
> print "\n";
> close (JOBS);
>
> This prints the first line of jobs.dat only.
> How can I have all the lines printed, one under the other?
>
> Thanks,
>
> Tony.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 14 Jul 2000 15:17:53 GMT
From: squidrocks@my-deja.com
Subject: Parameter passing
Message-Id: <396f2eeb.1798195@news.it.gvsu.edu>
Is it possible to pass parameters to suid?
------------------------------
Date: 14 Jul 2000 17:45:54 +0100
From: nobull@mail.com
Subject: Re: Parameter passing
Message-Id: <u9g0pcu0cc.fsf@wcl-l.bham.ac.uk>
squidrocks@my-deja.com writes:
> Is it possible to pass parameters to suid?
Is it possible to eat red?
Your question has no meaning.
It is possible to eat a red apple. The process is exactly the same as
eating a green apple.
It is possible to pass parameters to a suid script. It is exactly the
same as any other script.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 14 Jul 2000 16:59:38 +0100
From: "Cal Henderson" <cal@iamcal.com>
Subject: Re: Perl Expert? I need help!
Message-Id: <CNGb5.399$Ew5.9130@news6-win.server.ntlworld.com>
"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote...
:
: #!/usr/bin/perl -w
: use strict;
:
: my $a = "My name is Sylvain";
: $a =~ s/\s+//g;
: $a =~ s/^(.{8}).*$/$1/;
:
: print $a;
can this be done in a single reg ex?
--
Cal Henderson
sub a{my$a=reverse shift;$a=~y/b-z/a-y/;unshift@a,$a;}sub b{$c.=reverse
shift; while(length($c)>=$b[0]){a(substr($c,0,$b[0]));$c=substr($c,$b[0]);
shift@b;}}@b=(6,3,5,4,10,6,4,4,2,1);$a="l?jouipv"."ezvmxpbuxih";$a.=
",jofoqqibmzamsfsfxfjtuiIg";while($a ne ""){b(substr($a,0,2));$a=
substr($a,2);}print join(" ",@a);
------------------------------
Date: Fri, 14 Jul 2000 18:22:53 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Perl Expert? I need help!
Message-Id: <396F3E5D.5E024EEF@ife.ee.ethz.ch>
Cal Henderson wrote:
>
> "Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote...
> :
> : #!/usr/bin/perl -w
> : use strict;
> :
> : my $a = "My name is Sylvain";
> : $a =~ s/\s+//g;
> : $a =~ s/^(.{8}).*$/$1/;
> :
> : print $a;
>
> can this be done in a single reg ex?
Nope, you need a substitution or some other method that changes the
contents of $a
but here's one method that uses just one simple regexp:
$_ = $a;
$b = do {local $^W=0; #avoid warnings if length < 8
join '', (/\S/g)[0..7];
};
- Alex
------------------------------
Date: Fri, 14 Jul 2000 18:28:26 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl Expert? I need help!
Message-Id: <sbfumsg32po39njafnpti1l06t25h8amhb@4ax.com>
Sylvain2k wrote:
>I have a little problem. there it is:
>
>$a = "My name is Sylvain";
>
>I want to delete ALL spaces in this variable.
>I only want the first 8 caracters of the result.
First, delete stha spaces, e.g. using "tr///d". Then, using substr, get
the first eight characters.
print test("My name is Sylvain"), "\n";
sub test {
local $_ = shift;
tr/ //d;
if(int rand 2) {
print STDERR "Route 1\n";
substr($_, 8) = '';
return $_;
} else {
print STDERR "Route 2\n";
return substr $_, 0, 8;
}
}
--
Bart.
------------------------------
Date: 14 Jul 2000 17:16:09 +0100
From: nobull@mail.com
Subject: Re: Perl Expert? I need help!
Message-Id: <u9k8eou1py.fsf@wcl-l.bham.ac.uk>
"Sylvain2k" <sylvain2k@sympatico.ca> writes:
> (sorry... I'm a french canadian so my english is bad)
> I want to delete ALL spaces in this variable.
> I only want the first 8 caracters of the result.
You do not need an expert to help you with that.
A total beginner who has read the introductory texts should
be able to answer this question.
What you need is good book on Perl in French.
Many (most?) O'Reilly books are available in French.
http://www.editions-oreilly.fr/liste.html
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 14 Jul 2000 12:25:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Expert? I need help!
Message-Id: <slrn8mufne.dpf.tadmc@magna.metronet.com>
On Fri, 14 Jul 2000 18:22:53 +0200, Alex Rhomberg <rhomberg@ife.ee.ethz.ch> wrote:
>Cal Henderson wrote:
>>
>> "Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote...
>> :
>> : #!/usr/bin/perl -w
>> : use strict;
>> :
>> : my $a = "My name is Sylvain";
>> : $a =~ s/\s+//g;
>> : $a =~ s/^(.{8}).*$/$1/;
>> :
>> : print $a;
>>
>> can this be done in a single reg ex?
>
>Nope, you need a substitution or some other method that changes the
>contents of $a
>
>but here's one method that uses just one simple regexp:
>
>$_ = $a;
>
>$b = do {local $^W=0; #avoid warnings if length < 8
> join '', (/\S/g)[0..7];
> };
Here's a way using a single regex:
$a = ($a =~ s/\s+//g, substr($a, 0, 8));
But I don't see much point in forcing it into a single line or statement.
Much better to just be clear about what you are doing:
$a =~ s/\s+//g;
$a = substr($a, 0, 8);
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 Jul 2000 16:57:07 GMT
From: spock0000@my-deja.com
Subject: Re: perl prog to change UNIX password through CGI
Message-Id: <8kngop$kt3$1@nnrp1.deja.com>
You can type "system ("passwd")" the problem is that it runs a different
program but I don't know how to write the required passwords for that
program, maybe someone else can answer that.
In article <396dd536$1_2@nexus.comcen.com.au>,
"Kiel Stirling" <taboo@doofa.net> wrote:
>
> oct1pm@hotmail.com wrote:
> >Hi,>
> >I am trying to write a Perl CGI program so that when a user click
'reset
> >password' button through webpage, he can update his UNIX password.
> >One can type 'passwd' interactively to reset the password. Is there a
> >way I can reset it using something like "system("passwd")" in
Perl/CGI ?
> >
> >thanks for your info,
> >
> >Andrew
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Before you buy.
>
> Try looking at poppasswd or maybe if your running FreeBSD
> pw(8) which if your working on a localhost is more efficient.
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 14 Jul 2000 17:08:18 GMT
From: danno6000@hotmail.com
Subject: PerlScript on Win2K
Message-Id: <8knhdk$lcu$1@nnrp1.deja.com>
Has anyone successfully run an Active Server Page (3.0) using
PerlScript? I have ActivePerl 5.6 Build 615 installed on Win2K with
IIS5. Perl works fine from the command line, but I can't get the
PerlScript to function from ASP's.
Any insights would be great.
Thanks,
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 14 Jul 2000 17:04:54 GMT
From: danno6000@my-deja.com
Subject: PerlScript on Win2K
Message-Id: <8knh7n$o17$1@nnrp2.deja.com>
Has anybody successfully used PerlScript (from
ActiveState) with IIS5 and Active Server Pages on
Win2K?
I installed ActivePerl 5.6 build 615 and it works
fine from the command line, but I can't get
PerlScript to work from ASP's. I was logged in
as "administrator" when I did the install. The
install was fresh, meaning there wasn't an old
version of ActivePerl on the machine.
Thanks,
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 14 Jul 2000 17:55:16 GMT
From: "Propman" <propman@noemail.com>
Subject: POP3 password
Message-Id: <8uIb5.13947$V34.195662@news1.sttls1.wa.home.com>
I am looking for a Perl script that I can call from a simple web page to
allow users to change their POP3 passwords directly. I have found some, but
they require that I also compile and run C programs on my server as root,
which I can not do.
I've tried just piping the passwords into a system call to passwd, but that
doesn't seem to work (I could be doing something else wrong, I've very new
to Perl).
Any advice or pointers to links would be nice...
--propman
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3669
**************************************