[22427] in Perl-Users-Digest
Perl-Users Digest, Issue: 4648 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 1 18:05:43 2003
Date: Sat, 1 Mar 2003 15:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 1 Mar 2003 Volume: 10 Number: 4648
Today's topics:
Re: Expression Help <jurgenex@hotmail.com>
Re: Expression Help (Anno Siegel)
Re: Expression Help <noreply@gunnar.cc>
Re: grep command in a perl script (David Efflandt)
Re: help with printing an array of strings (Anno Siegel)
Perl Pager Script (simple beep) <kumpf@mit.edu>
Re: Perl Pager Script (simple beep) <jurgenex@hotmail.com>
Re: Perl Pager Script (simple beep) (Jay Tilton)
Re: Reading tab delimited files into a hash. <goldbb2@earthlink.net>
Re: recursively adding arrays of arrays (Anno Siegel)
Re: recursively adding arrays of arrays <someone@somewhere.nl>
Re: Send .tgz files <bart.lateur@pandora.be>
Re: Sending mulitple lines of text in email problem <noreply@gunnar.cc>
string manipulations (david)
Re: string manipulations (Tad McClellan)
Re: string manipulations (Tad McClellan)
Using the Param method of CGI <geoff.news6@alphaworks.co.uk>
Re: Using the Param method of CGI <bwalton@rochester.rr.com>
Re: Using the Param method of CGI <peakpeek@purethought.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 01 Mar 2003 16:19:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Expression Help
Message-Id: <m458a.51409$_J5.10732@nwrddc01.gnilink.net>
montecristo@nospamspamcop.net wrote:
> In article <b3qkr3$1ov27q$1@ID-184292.news.dfncis.de>,
> noreply@gunnar.cc says...
>> montecristo@nospamspamcop.net wrote:
>>> I learning Perl on the fly
>>
>> Exactly what does that mean? Does it mean that you are not willing to
>> try solving a problem by studying the docs, FAQs and other sources at
>> first hand? In that case you shouldn't count on help in this group.
>>
> It means I'm new. I did study the docs. Just didn't find anything that
> seemed to solve my problem, that's why I asked. Like I said in an
> earlier post, I didn't know you could use "and".
Well, ok, fair enough.
However, at least any programming I know of has some operator or function to
perform a boolean "and". Some call is "and", some call it "&", some call it
"&&", some call it "AND" and the exact functionality may be a bit different
(bitwise, logical, ...) from language to language. Those are details you
have to look up in the language manual.
But a language without a boolean "and"? Hard to imagine.... Well, maybe
assembler.
jue
------------------------------
Date: 1 Mar 2003 16:24:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Expression Help
Message-Id: <b3qmrm$387$1@mamenchi.zrz.TU-Berlin.DE>
<montecristo@nospamspamcop.net> wrote in comp.lang.perl.misc:
> I learning Perl on the fly here so please be kind.
> Is there a operator that will fulfill this requirement? "Greater than a
> number, but less than another?"
That's what you think you need to solve the problem, but you don't.
> The problem I'm having with the snipet of code below is that
> "$shipqtysubtotal" will always show up as some number less than 15 if
> "$AllOthers" isn't ordered.
"Ordered"? What do you mean by that? If you use terms specific to
your problem area you must explain them. Your readers must look at the
code to tediously guess that it means something like "is not zero".
> I've tried setting "$shipqtysubtotal" to ""
> but that didn't help either.
In the current code you set it to "0". Why would you set a variable that
is later only used in calculations to a string? If anything, it would make
sense to set it to 0. As you have seen, that isn't the problem. However,
you don't seem to run your code with warnings enabled. Do so, and make
it run clean. You should do that before you post it.
> I don't want to add shipping charges to an item that isn't ordered.
If by "add shipping charges" you mean "add $shipping (from the code below)
to something else" that is a different question again. I'm tired of
speculating and stick to the first one.
[snip irrelevant code]
> if ($I eq 'Custom Work' ) { $shipping = 0 }
> elsif ( $AllOthers <= 15 ) {$shipqtysubtotal = 6.00}
> elsif ( $AllOthers <= 30 ) {$shipqtysubtotal = 7.95}
> elsif ( $AllOthers <= 45 ) {$shipqtysubtotal = 9.95}
> elsif ( $AllOthers <= 60 ) {$shipqtysubtotal = 11.95}
> elsif ( $AllOthers <= 75 ) {$shipqtysubtotal = 13.95}
> elsif ( $AllOthers > 75 ) {$shipqtysubtotal = (.05 * $p)}
>
> $shipping = ($FlaggedSpecialItems + $FlaggedNoteCards +
> $shipqtysubtotal);
Your "if/elsif" structure is all wrong. A strong indication is that the
"if"-part talks about one set of variables ($I, $shipping) and all the
"elsif"s talk about another ($AllOthers, $shipqtysubtotal). Without even
looking at the context, this is almost certainly wrong. Also note that
setting $shipping in the "if"-clause is useless because later you are
setting it unconditionally to something else. Most probably you mean:
if ( $I eq 'Custom Work' ) {
$shipping = 0;
} else {
if ( $AllOthers <= 0 ) {$shipqtysubtotal = 0.00}
elsif ( $AllOthers <= 15 ) {$shipqtysubtotal = 6.00}
elsif ( $AllOthers <= 30 ) {$shipqtysubtotal = 7.95}
elsif ( $AllOthers <= 45 ) {$shipqtysubtotal = 9.95}
elsif ( $AllOthers <= 60 ) {$shipqtysubtotal = 11.95}
elsif ( $AllOthers <= 75 ) {$shipqtysubtotal = 13.95}
elsif ( $AllOthers > 75 ) {$shipqtysubtotal = (.05 * $p)}
$shipping = ($FlaggedSpecialItems + $FlaggedNoteCards +
$shipqtysubtotal);
}
Here, $shipping is set one way or the other. Also note that I have
added a new clause to the "if/elsif" that takes care of the case that
$AllOthers is 0 (and < 0). If that is indeed what you mean by "not
ordered", that will solve your original problem.
Anno
------------------------------
Date: Sat, 01 Mar 2003 22:07:20 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Expression Help
Message-Id: <b3r8i8$1p2fbm$2@ID-184292.news.dfncis.de>
montecristo@nospamspamcop.net wrote:
> In article <b3qkr3$1ov27q$1@ID-184292.news.dfncis.de>, noreply@gunnar.cc
> says...
>
>>montecristo@nospamspamcop.net wrote:
>>>I learning Perl on the fly
>>
>>Exactly what does that mean? Does it mean that you are not willing to
>>try solving a problem by studying the docs, FAQs and other sources at
>>first hand? In that case you shouldn't count on help in this group.
>
> It means I'm new. I did study the docs. Just didn't find anything that
> seemed to solve my problem, that's why I asked. Like I said in an
> earlier post, I didn't know you could use "and".
Okay, my apologies for the insinuating response. Note, though, that
starting a post that way isn't advisable, since there obviously are
quite a few posters who don't know about, or don't care to comply with,
the posting guidelines.
> Thanks for your help.
You are welcome. ;-) But maybe Anno's response was more useful to you.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 1 Mar 2003 16:37:51 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: grep command in a perl script
Message-Id: <slrnb61oev.gn2.efflandt@typhoon.xnet.com>
On 1 Mar 2003 07:58:16 -0800, Bakechad <bakechad@ameritech.net> wrote:
> I am new to perl and programming in general. I grinded out the script
> below to convert color files to greyscale. The script works, but I
> would like to ignore the case in my grep statement to pickup files
> with both a .jpg & .JPG extension. I keep trying to add a -i to the
> grep statement, but no matter what syntax I try, it does not work.
>
> Thanks
>
> Chad
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use Image::Magick;
>
> my ($appfile, $extension, $startdir, $destdir, $of, $image, $fname,
> $pextension)
> ;
> $appfile = "_bw.";
> $extension = "jpg";
> my $cl1 = $ARGV[0];
> $startdir = "$cl1";
> $destdir = "$startdir/bw";
> if (not -d $destdir) {
> mkdir ($destdir);
> }
> opendir("photos", $startdir);
> my @files = readdir("photos");
> closedir("photos");
> my @ofs = grep /.jpg/, @files;
Note that a dot matches any character (wildcard) and above in filename
terms would match *jpg* anywhere in the filename (including .jpg.exe
worms). So you probably want to escape the dot and bind it to end of
filename with case insensitive switch:
my @ofs = grep /\.jpg$/i, @files;
> foreach $of (@ofs) {
> ($fname, $pextension) = split(/\./, $of);
You knew enough to escape the dot here, but how to you know that the
filename only has 1 dot (Unix files can have multiple dots)? For example
your split would split some.other.jpg into "some" and "other.jpg" If you
are trying to grab the filename extenstion you probably want to grab text
before and after the _last_ dot:
foreach $of (@ofs) {
if ($of =~ /^(.+)\.([^.]+)$/) {
($fname,$pextension) = ($1,$2);
} else {
#warn "can't parse $of\n"; # uncomment for testing
next; # skip to next $of
}
# do something useful with $fname $pextension
}
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 1 Mar 2003 16:51:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help with printing an array of strings
Message-Id: <b3qodt$4cd$1@mamenchi.zrz.TU-Berlin.DE>
Barry Kimelman <barryk2@SPAM-KILLER.mts.net> wrote in comp.lang.perl.misc:
>
> In article <gnO7a.580$%v1.358@newssvr16.news.prodigy.com>, manj dodda
> (dmanjunath@yahoo.com) says...
> > I have an array of strings like,
> >
> > $array[0] = "my name is Henry" ;
> > $array[1] = "What is yours" ;
> > $array[2] = "Food" ;
> >
> > now i want to print the array with the max len of array[0] which will be
> > 16. How do i do it ?.
> >
> > my $maxlen = 16 ;
> > for($i=0; $i <= $#array ; $i++){
> > printf HANDLE("%s", $array[$i]) ;
> > }
> >
> > Thanks in advance
> >
> > md
>
> # calculate length of longest element in array
> $maxlen = (reverse sort { $a <=> $b } map { length $_ } @array)[0];
Using sort to find the maximum is the quick and dirty way. It's quick
on programmer time and dirty on system resources, so it may well be the
right way. I only mention it because it isn't the only way. It's
definitely wrong with very long lists.
> for ( $i = 0 ; $i <= $#array ; ++$i ) {
> printf HANDLE "%-${maxlen}.${maxlen}s\n",$array[$i];
> }
Useless use of index. In Perl:
printf HANDLE "%-${maxlen}.${maxlen}s\n", $_ for @array;
I agree with the use of {} around "maxlen" in both cases, even tough
only the second one requires them. It makes it easy to spot that the
same thing is interpolated twice. The reader understands and is pleased.
Anno
------------------------------
Date: Sat, 1 Mar 2003 13:42:08 -0500
From: "Adam Kumpf" <kumpf@mit.edu>
Subject: Perl Pager Script (simple beep)
Message-Id: <3e60fef6$0$3959$b45e6eb0@senator-bedfellow.mit.edu>
I am looking at making a simple Perl/CGI pager script beeps my PC speaker
when a user clicks on a button on my website. I am running ActivePerl on a
windows box. The problem is that I can't make it beep on my computer from a
remote user. I can run the script on my desktop and hear the beep, but when
load the page through my webserver, the beep is gone. I believe that it is
sending the beep to the client's browser window instead of to my pc speaker.
I'm just using a simple command:
print "\a"; # "(a)larm"
Is there any way to print it to my computer instead of to the client's?
Thanks for your time.
Best Regards,
Adam Kumpf
kumpf@mit.edu
http://web.mit.edu/kumpf
------------------------------
Date: Sat, 01 Mar 2003 19:08:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl Pager Script (simple beep)
Message-Id: <yy78a.51997$_J5.42576@nwrddc01.gnilink.net>
Adam Kumpf wrote:
> I am looking at making a simple Perl/CGI pager script beeps my PC
> speaker when a user clicks on a button on my website. I am running
> ActivePerl on a windows box. The problem is that I can't make it
> beep on my computer from a remote user. I can run the script on my
> desktop and hear the beep, but when load the page through my
> webserver, the beep is gone. I believe that it is sending the beep
> to the client's browser window instead of to my pc speaker. I'm just
> using a simple command:
>
> print "\a"; # "(a)larm"
>
> Is there any way to print it to my computer instead of to the
> client's?
You seem to be utterly confused about how CGI programs, Perl, websites,
servers, clients, your PC, remote users, .... interact.
The Perl part you got right already.
The rest of your question has nothing to do with Perl and you may want to
ask in NG that actually deals with CGI, websites, servers, clients, your
PC, remote users, ..
<WildOffTopicGuess>
The output of a program that is run by a CGI server is piped to the CGI
server, processes, and then sent to the client.
If you want a CGI script to output something on the server you should
remember that normally there is no terminal associated with the server. So
where should that beep appear if there is no terminal?
And talking about your PC: Well, the web server would have to open some
channel to your PC and then send the beep via that channel. I can imagine
that there are many ways how you could do that, e.g. IPC or IM or .... .
First you should find out which method you want to use, then you are welcome
to ask how to implement this in Perl. Most likely there is a module already
that does most of the hard work.
</WildOffTopicGuess>
jue
------------------------------
Date: Sat, 01 Mar 2003 19:52:37 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Perl Pager Script (simple beep)
Message-Id: <3e61084f.69346451@news.erols.com>
"Adam Kumpf" <kumpf@mit.edu> wrote:
: I can run the script on my desktop and hear the beep, but when
: load the page through my webserver, the beep is gone.
: I believe that it is sending the beep to the client's browser window
: instead of to my pc speaker.
:
: I'm just using a simple command:
:
: print "\a"; # "(a)larm"
The beep is the console's way of representing the "\a" character. The
STDOUT handle is not attached to the console in a CGI environment, so
you'll need to explicitly open a handle to the console and send "\a"
there.
On a Windows box, the console device is represented by the
'con' pseudo-file.
#!perl
print <<EOF;
Content-type: text/html
<html><body><p>Hello, world!</body></html>
EOF
if( open BEEPER, '>', 'con' ) {
print BEEPER "\a";
close BEEPER;
}
------------------------------
Date: Sat, 01 Mar 2003 12:47:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <3E60F23B.FBC29C88@earthlink.net>
"Charles R. Thompson" wrote:
>
> > : my $hostsfile = &read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
> >
> > If you must slurp the file (and you probably don't), slurp into an
> > array instead of a single scalar. It will make line-by-line
> > processing easier than having to do that s/^CLIENT:....\n// jazz.
> >
> > my @hostsfile = read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
>
> This has been something I've done for awhile and thinking back I
> remeber playing with Benchmark and finding the array to be a bit
> slower on the processing end of things, especially with large files. I
> might be confusing that with something else though. Am I wrong there
> on the speed issue?
No, you are quite correct -- it's generally slower to slurp the data
into an array and iterate over it, than it is to read a file line by
line.
The only time there's an advantage in slurping into an array is if you
need to iterate over it in a nested loop.... Something like:
foreach my $foo (@the_data) {
foreach my $bar (@the_data) {
# ...do stuff...
}
}
In this kind of situation, it would be rather awkward (slow) to read the
file line-by-line.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: 1 Mar 2003 17:21:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: recursively adding arrays of arrays
Message-Id: <b3qq61$4cd$2@mamenchi.zrz.TU-Berlin.DE>
ravlin <jhayden@usa.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> I'm thinking there's an easy solution to this problem. I've been trying to
> come up with it for the last couple days, but haven't been able to. I'm
> trying to write a function that will parse a file.
So you want to write a parser.
> This file contains a list
> of tests I want to run. Everytime it comes to a line with a "{", I want to
> start a new array so as I go deeper into blocks of data, I can keep things
> sorted out. I'm probably confusing you, so let me give you an example.
> Everything to the right of the # is what I want the value to be in perl.
>
> { # $testgroup[0]
> var1=1 # $testgroup[0]{'vars'}[0] = "var1=1"
> var2=2 # $testgroup[0]{'vars'}[1] = "var2=2"
> { # $testgroup[0][0]
These are nested structures. Use Parse::RecDescent.
[snip rest]
Anno
------------------------------
Date: Sat, 1 Mar 2003 18:33:04 +0100
From: "Stefan" <someone@somewhere.nl>
Subject: Re: recursively adding arrays of arrays
Message-Id: <3e60f027$0$156$e4fe514c@dreader7.news.xs4all.nl>
"ravlin" <jhayden@usa.com> schreef in bericht
news:pG28a.57211$If5.3162089@twister.southeast.rr.com...
> Hi all,
>
> I'm thinking there's an easy solution to this problem. I've been trying
to
> come up with it for the last couple days, but haven't been able to. I'm
> trying to write a function that will parse a file. This file contains a
list
> of tests I want to run. Everytime it comes to a line with a "{", I want
to
> start a new array so as I go deeper into blocks of data, I can keep things
> sorted out. I'm probably confusing you, so let me give you an example.
> Everything to the right of the # is what I want the value to be in perl.
>
> { # $testgroup[0]
> var1=1 # $testgroup[0]{'vars'}[0] = "var1=1"
> var2=2 # $testgroup[0]{'vars'}[1] = "var2=2"
> { # $testgroup[0][0]
> { # $testgroup[0][0][0]
> var3=3 # $testgroup[0][0][0]{'vars'}[0] = "var3=3"
> { # $testgroup[0][0][0][0]
> test1 # $testgroup[0][0][0][0]{'test'}[0] = "test1"
> test2 # $testgroup[0][0][0][0]{'test'}[1] = "test2"
> }
> { # $testgroup[0][0][0][1]
> }
> }
> { # $testgroup[0][0][1]
> test3 # $testgroup[0][0][1][0]{'test'}[0] = "test3"
> test4 # $testgroup[0][0][1][0]{'test'}[1] = "test4"
> }
> }
> }
>
> This is a simple example. Basically, each test will pick up different
> values depending on where they are located in this file. So the variable
> var1 and var2 will be seen by all 4 tests, but var3 will only be seen by
> test1 and test2, but not test3 and test4. So, the scope of each test is
> important. I'm not a great perl programmer so maybe I'm going about it
all
> wrong and don't want to use arrays of arrays (of hashes). It seems pretty
> straight forward to me looking at the example I have, but I just can't
> figure out he code to keep adding on more arrays (and then taking them off
> as the blocks close). Thanks for ANY help or direction you can give me.
>
> Jon
I wouldn't go there since it's getting you nowhere. I couldn't even figure
out what you're trying to accomplish.
Instead of building arrays-of-arrays-of-arrays-etc try generating a keyword
for a associative hashed array. Much easier to "dump" too when your
debugging. The value don't need to be strings but can be arrays too.
When in your example an array is identified as
$testgroup[0][0][1][0]{'test'}[0] the keyword would be (for example using
underscores) "0_0_1_0_test_0".
It doesn't do a thing for your test-scope.s That's something which you need
to implement in the logics of your program.
Just an idea - hopefully it will guide you in the right direction.
Stefan
------------------------------
Date: Sat, 01 Mar 2003 20:32:10 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Send .tgz files
Message-Id: <e0626v0bcfvfrh1vrrj01al5dofsi0lvc1@4ax.com>
Jake wrote:
>How do I, via perl or shell code, attach a .tgz file and email it to
>someone? I'd like to do this hopefully without having to install
>third-party .pm modules if possible. Thanks.
Attach (and send): via the module MIME::Lite
Creating the .tgz file: either via tar (+ gzip) (`tar -czf file.tgz -C
$dir .`) or via the module Archive::Tar, which can create compressed tar
files if the module Compress::Zlib is also installed.
Wihout installing 3rd party modules? That's harder.
--
Bart.
------------------------------
Date: Sat, 01 Mar 2003 22:07:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sending mulitple lines of text in email problem
Message-Id: <b3r8i1$1p2fbm$1@ID-184292.news.dfncis.de>
Eric J. Roode wrote:
> "Robert" <robert.j.sipe@boeing.com> wrote in
> news:HB1Jsz.362@news.boeing.com:
>
>>and need to include a list. Currently the list is an array; @{$_[0]}.
>> The problem is the array is wrapping (as one would expect). I can't
>>come up with a way to include the list into my here doc so it is in a
>>column format.
>
> Perhaps set $" to "\n" and then just include @{$_[0]} in the here-doc?
That's obviously a more efficient method than my using the join function
to store the list in a scalar variable.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 1 Mar 2003 08:42:24 -0800
From: dwlepage@yahoo.com (david)
Subject: string manipulations
Message-Id: <b09a22ae.0303010842.7856e4ab@posting.google.com>
I am new to perl (have worked with AWK in the past) and have to do
string manipulations, on an existing data file, which ive heard is
easier to do in perl in my case. What would be the best way to go
about doing this.
Here is what my data file looks like:
dn: UserId=dlepage,User
objectclass: User
ldifGroup: Groupname
Comment: 5XY2QD3
ModifiedBy: dave
ModificationDateTime: 2003/02/27 17:23:46.207 (GMT)
UserId: dlepage
PasswdId: 1:dlepage.password
dn: AuthenticatorId=dlepage.password, Authenticator
objectclass: Authenticator
StoredAt: AuthenticatorId=dlepage.password
EntryId: Authenticator-dlepage.password-2003/01/28 13:10:08.943 (GMT)
(on 10.65.63.140:5040)-2039
AuthenticatorId: dlepage.password
What I want to do is find the value in comments:
5XY2QD3
the value in the users AuthenticatorID:
dlepage.passsword
and replace this value with any instance of 'dlepage.password' in the
file.
I can find ways to do this with 1 user, but I have thousands, so each
comment field and 'authenticatorID' will be unique.
dn: UserId=dlepage,User
objectclass: User
ldifGroup: Groupname
Comment: P08233
ModifiedBy: dave
ModificationDateTime: 2003/02/27 17:23:46.207 (GMT)
UserId: dlepage
AuthenticatorId: 1:5XY2QD3
dn: AuthenticatorId=5XY2QD3, Authenticator
objectclass: Authenticator
StoredAt: AuthenticatorId=5XY2QD3
EntryId: Authenticator-5XY2QD3-2003/01/28 13:10:08.943 (GMT) (on
10.65.63.140:5040)-2039
AuthenticatorId: 5XY2QD3
What ive got so far is very basic. Im trying to figure out what the
best way to do this is. Find the values of all 'dn: UserId=' and store
these in an array, and do the same for 'comment'? then join/replace?
open(LDIF, "<testfile.ldif");
while (<LDIF>) {
/dn:\ssccUserId\=/;
@users=$';
chomp @users;
}
print "@users";
close(LDIF);
thanks,
------------------------------
Date: Sat, 1 Mar 2003 14:57:24 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string manipulations
Message-Id: <slrnb627lk.3p2.tadmc@magna.augustmail.com>
david <dwlepage@yahoo.com> wrote:
> Here is what my data file looks like:
>
> dn: UserId=dlepage,User
> objectclass: User
> ldifGroup: Groupname
> Comment: 5XY2QD3
> ModifiedBy: dave
> ModificationDateTime: 2003/02/27 17:23:46.207 (GMT)
> UserId: dlepage
> PasswdId: 1:dlepage.password
>
> dn: AuthenticatorId=dlepage.password, Authenticator
> objectclass: Authenticator
> StoredAt: AuthenticatorId=dlepage.password
> EntryId: Authenticator-dlepage.password-2003/01/28 13:10:08.943 (GMT)
> (on 10.65.63.140:5040)-2039
> AuthenticatorId: dlepage.password
I'll assume that you have that multiline string already stored in $_.
> What I want to do is find the value in comments:
> 5XY2QD3
my $replace = $1 if /^Comment:\s+(.*)/m;
> the value in the users AuthenticatorID:
> dlepage.passsword
my $search = $1 if /^AuthenticatorId:\s+(.*)/m;
> and replace this value with any instance of 'dlepage.password' in the
> file.
s/$search/$replace/g;
> open(LDIF, "<testfile.ldif");
You should always, yes *always*, check the return value from open():
open(LDIF, "<testfile.ldif") or die "could not open 'testfile.ldif' $!";
> while (<LDIF>) {
> /dn:\ssccUserId\=/;
^^^^^^^^^^^
Why are you trying to match the string "sccUserId"?
It does not appear in your data, the match must always fail.
You do not need to escape an equals sign in regexes, it is not special.
> @users=$';
Why are you trying to store a single thing in an array?
You should use capturing parenthesis instead of the $`, $& and $'
variables, they slow down your program for no good reason.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 1 Mar 2003 14:58:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string manipulations
Message-Id: <slrnb627nm.3p2.tadmc@magna.augustmail.com>
david <dwlepage@yahoo.com> wrote:
> Here is what my data file looks like:
[snip]
> Comment: 5XY2QD3
> and replace this value with any instance of 'dlepage.password' in the
> file.
> Comment: P08233
Why did that value change?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 1 Mar 2003 19:50:22 -0000
From: "Geoff Soper" <geoff.news6@alphaworks.co.uk>
Subject: Using the Param method of CGI
Message-Id: <3e610f01$0$6301$cc9e4d1f@news.dial.pipex.com>
I think this is more of a Perl query than a CGI query. I'm trying to use
Param method of CGI to create a hash of all the pairs of names and value
that make up the parameters of a CGI script so that I may pass it as a
reference into a subroutine. My problem is a lack of understanding of the
relevant man page. I'm confused by the different effect of calling Param in
a scalar or list context. I'm also not sure what a tied hash reference is
which is what is returned when Param is called in a scalar context. Which
context do I need and how should I pass the hash to the subroutine? I'm also
slightly concerned by what it says about watching out for multivalued CGI
parameters but I'll put off worrying about that just now!
Thanks
Geoff
------------------------------
Date: Sat, 01 Mar 2003 21:20:10 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Using the Param method of CGI
Message-Id: <3E6123F0.1010707@rochester.rr.com>
Geoff Soper wrote:
> I think this is more of a Perl query than a CGI query. I'm trying to use
> Param method of CGI to create a hash of all the pairs of names and value
--^^^^^
I assume you mean the param method. Case is important. There is no
Param method documented in the CGI module (although I see there is
something by that name, but it seems to return the empty string in my
tests).
> that make up the parameters of a CGI script so that I may pass it as a
> reference into a subroutine. My problem is a lack of understanding of the
> relevant man page. I'm confused by the different effect of calling Param in
> a scalar or list context. I'm also not sure what a tied hash reference is
-----------------------------------------------------^^^^
Where do the docs say that??
> which is what is returned when Param is called in a scalar context. Which
What CGI module are you using? When param is called with no arguments
in a scalar context, the result in the scalar is the number of parameters.
> context do I need and how should I pass the hash to the subroutine? I'm also
> slightly concerned by what it says about watching out for multivalued CGI
> parameters but I'll put off worrying about that just now!
...
> Geoff
If you are trying to get a reference to a hash which contains the names
and values of your CGI parameters, the param method is not the most
convenient. Try the Vars method:
$hash_ref=$q->Vars;
You can pass this to a sub by:
subname($hash_ref);
...
sub subname{
my $sub_hash_ref=shift;
print $sub_hash_ref->{name_of_a_parameter};
}
for example [untested]. The CGI module docs are quite clear on all this.
It is also quite clear on what to do with multivalued parameters.
You have been reading:
perldoc CGI
haven't you?
--
Bob Walton
------------------------------
Date: Sat, 01 Mar 2003 22:53:00 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Using the Param method of CGI
Message-Id: <7cd26vkacaefuuaok1grr16j618k1eb572@4ax.com>
On Sat, 1 Mar 2003 19:50:22 -0000, in comp.lang.perl.misc, "Geoff Soper" <geoff.news6@alphaworks.co.uk> wrote:
>I think this is more of a Perl query than a CGI query. I'm trying to use
>Param method of CGI to create a hash of all the pairs of names and value
>that make up the parameters of a CGI script so that I may pass it as a
>reference into a subroutine
As Mr Walton wrote elsewhere in this thread, CGI.pm has a Vars()
method which copies all the parameters into a hash
But if all you want to do is pass the CGI parameters into a
subroutine, you could pass the CGI object itself ...
#!/usr/bin/perl -T
use strict; use warnings;
use CGI;
my $query = new CGI;
do_something($query);
print $query->header, $query->start_html, $query->Dump, $query->end_html;
sub do_something {
my $query = shift;
# something
}
--
Sharon
------------------------------
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 4648
***************************************