[17434] in Perl-Users-Digest
Perl-Users Digest, Issue: 4854 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 9 09:05:40 2000
Date: Thu, 9 Nov 2000 06:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973778712-v9-i4854@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 9 Nov 2000 Volume: 9 Number: 4854
Today's topics:
A Disk Space problem <jamesmckay@MailAndNews.com>
Re: A Disk Space problem (Martien Verbruggen)
RE: A Disk Space problem <jamesmckay@MailAndNews.com>
Any way to send a Win-Message to WINNT from Perlscript? <mmarks@gfma.de>
Re: Detecting socket closure <fulko@wecan.com>
fileevent not working in Perl Tk for NT <ian_mackenzie@agilent.com>
Re: getgrgid does not work with nis (perl 5.6.0) <Olivier.Lacroix@ciril.fr>
Re: Hash assignments in loops? <julien.quint@xrce.xerox.com>
Re: Help -- msgget with key >= 0x80000000 fails <geoff-at-farmline-dot-com@127.0.0.1>
Re: Help -- msgget with key >= 0x80000000 fails (Ilya Zakharevich)
Re: Help with HTML::Parser module <joe+usenet@sunstarsys.com>
Re: Help with HTML::Parser module <bart.lateur@skynet.be>
Re: Help with HTML::Parser module <julien.quint@xrce.xerox.com>
Re: Help with HTML::Parser module <joe+usenet@sunstarsys.com>
how do I process multiple selections? (ntl)
Re: how do I process multiple selections? (Martien Verbruggen)
Re: how do I process multiple selections? nobull@mail.com
Re: how do I process multiple selections? <james@NOSPAM.demon.co.uk>
Re: I do not Understand Perl Formats <bart.lateur@skynet.be>
Last 128 bytes of xxx files? <damir.boraska@hrt.hr>
Re: Need Help with a Regular Expression <bart.lateur@skynet.be>
Passing Reference <vidulats@yahoo.co.uk>
Perl Registry Entries hosed? <incubus@hawaii.rr.com>
Re: Perl vs. ActivePerl (newbie) <preetham@india.hp.com>
Re: Pushing a hash on to a stack... <james@NOSPAM.demon.co.uk>
Re: reconstituting hash from reference? <bart.lateur@skynet.be>
Re: reconstituting hash from reference? <stephenk@cc.gatech.edu>
Re: strip html tags from string $text <damir.boraska@hrt.hr>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 9 Nov 2000 06:19:34 -0500
From: James <jamesmckay@MailAndNews.com>
Subject: A Disk Space problem
Message-Id: <3A182B3E@MailAndNews.com>
Hi,
Quick question: Is there a built-in method for finding out disk space
statistics on NT4 using ActivePerl? I know I could do it by trapping the
output of the "dir" command via a system() call, but that seems very crude.
Any thoughts?
Thanks in advance
James
------------------------------
Date: Thu, 9 Nov 2000 23:14:59 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: A Disk Space problem
Message-Id: <slrn90l5a3.22p.mgjv@martien.heliotrope.home>
On Thu, 9 Nov 2000 06:19:34 -0500,
James <jamesmckay@MailAndNews.com> wrote:
> Hi,
> Quick question: Is there a built-in method for finding out disk space
> statistics on NT4 using ActivePerl? I know I could do it by trapping the
> output of the "dir" command via a system() call, but that seems very crude.
Not a builtin Perl command, no. Disk space statistics are very platform
dependent, even between platforms that are similar. Capturing the output
of a dir might not be so bad. On unices, I normally call out to df, and
capture that output. It's the most 'portable' way to do it there,
although there are still differences.
However, search.cpan.org lists Win32::API, which probably has a windows
specific call that you can use directly, and Win32::DriveInfo, which should
give you this sort of detail. I haven't looked at their documentation,
but it looks like they could be useful to you.
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Thu, 9 Nov 2000 07:37:35 -0500
From: James <jamesmckay@MailAndNews.com>
Subject: RE: A Disk Space problem
Message-Id: <3A19D772@MailAndNews.com>
Thanks Martien,
that was perfect.
Regards
James
>===== Original Message From mgjv@tradingpost.com.au =====
>On Thu, 9 Nov 2000 06:19:34 -0500,
> James <jamesmckay@MailAndNews.com> wrote:
>> Hi,
>> Quick question: Is there a built-in method for finding out disk space
>> statistics on NT4 using ActivePerl? I know I could do it by trapping the
>> output of the "dir" command via a system() call, but that seems very crude.
>
>Not a builtin Perl command, no. Disk space statistics are very platform
>dependent, even between platforms that are similar. Capturing the output
>of a dir might not be so bad. On unices, I normally call out to df, and
>capture that output. It's the most 'portable' way to do it there,
>although there are still differences.
>
>However, search.cpan.org lists Win32::API, which probably has a windows
>specific call that you can use directly, and Win32::DriveInfo, which should
>give you this sort of detail. I haven't looked at their documentation,
>but it looks like they could be useful to you.
>
>Martien
>--
>Martien Verbruggen |
>Interactive Media Division | We are born naked, wet and hungry.
>Commercial Dynamics Pty. Ltd. | Then things get worse.
>NSW, Australia |
------------------------------
Date: Thu, 09 Nov 2000 12:28:55 +0100
From: Matthias Marks <mmarks@gfma.de>
Subject: Any way to send a Win-Message to WINNT from Perlscript?
Message-Id: <3A0A8A77.F8F8F76@gfma.de>
Hallo,
I want to send a Message to an application running under NT.
Does anybody know a functionmodule to send a WinMessage ??
--
MFG Matthias Marks
mmarks@gfma.de oder priv. M.Marks@gmx.de
P.S.: Wirf Deinen Lendenschurz nicht fort,
wenn Du ein neues Kleid bekommen hast !
Sprichwort aus dem Kongo
------------------------------
Date: Thu, 09 Nov 2000 08:55:56 -0500
From: Fulko Hew <fulko@wecan.com>
Subject: Re: Detecting socket closure
Message-Id: <3A0AACEC.15FB@wecan.com>
Charles DeRykus wrote:
> >Keep in mind that the program wasn't terminating, it was blocking
> >in send().
> >
> >I suspect if you set it to ignore (I haven't tried it) then
> >the signal won't be delivered, and the send() won't get interrupted.
> >and I'm back to being blocked.
> >
>
> No, I don't believe that's true. Even if the signal's ignored,
> errno gets set. For instance, here's a simple client/server
> pair which causes the client to terminate with:
>
> "send: Broken pipe at ./client.pl line 18"
>
> The server simply closes the socket before the client
> can finish sending a large amount of data to force the
> SIGPIPE.
Ahh, well when I create and run simple test programs, it works too.
When I run my real production code, it is intermittent (mostly missing).
I've also found out that the IP stack, and CPU speed/loading also
affect that intermitancy. Its as if there is some weird timing
relationship that causes things to line up "just so" to cause it to
fail. Any hardware or software change, can alter that timing.
I have production code that is guaranteed to fail on a 133Mhz RedHat 6.2
that occasionally works on a 200Mhz RedHat 6.2 box and that works find
on a 600Mhz RedHat 6.2 box. If I add a print statement, the 200Mhz box
works infinitely more reliably, but the 133 still fails.
Since its timing related, I'm afraid that in production, CPU loading
could put this code into the failure mode.
------------------------------
Date: Thu, 9 Nov 2000 13:39:19 -0000
From: "Ian Mackenzie" <ian_mackenzie@agilent.com>
Subject: fileevent not working in Perl Tk for NT
Message-Id: <3a0aa90a@hpsqftk>
I have a PerlTk program that uses sockets with the fileevent
set to call the callback sub when the socket filehandle is readable,
this works fine in unix but in WINNT the filevent calls ths callback
sub even when there is no connection to the socket filehandle, has ANYONE
found a fix to this dammed problem
socket section :
############################################################################
###
####
#
# Set up socket connect to port 3001
#
############################################################################
####
####
socket(SERVER,PF_INET,SOCK_STREAM, getprotobyname('tcp'));
setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1);
$addr = sockaddr_in(3001,inet_aton($hostname));
bind(SERVER,$addr)
or die "Could not bind to port\n";
listen(SERVER,SOMAXCONN)
or die "Could not listen to port\n";
$|=1;
Fileevent section :
############################################################################
####
######
# set up main_frame file_event to enables external commands to take action
#
############################################################################
####
#####
$main_frame->fileevent(SERVER,'readable',[\&parse_socket]);
The parse_socket sub is called immediatly, i.e the event does not wait until
there is activity on the socket filehandle SERVER
Any clues anyone, I am using perl 5.6 from ActivePerl
------------------------------
Date: Thu, 09 Nov 2000 12:15:18 +0100
From: Olivier LACROIX <Olivier.Lacroix@ciril.fr>
Subject: Re: getgrgid does not work with nis (perl 5.6.0)
Message-Id: <3A0A8746.A15AE441@ciril.fr>
Ren Maddox a écrit :
> Olivier LACROIX <Olivier.Lacroix@ciril.fr> writes:
>
> > Hello.
> >
> > I have a problem with getgrgid (and with all commend getgr*). It returns
> > the correct value for all local groups, but returns NULL value for all
> > groups in the NIS database. I think there is a bug, because all commands
> > getpw* work (even with NIS).
>
> Check the /etc/group file for the + line at the bottom. If that is
> missing then NIS will not be used for group resolution. (At least,
> that's the way I remember it, it's been several years since I've used
> NIS.)
>
> --
> Ren Maddox
> ren@tivoli.com
Thanks for your help, but it was not a probleme with NIS, beacause the
getgrgid works with a C program.
I have rebuilt perl with gcc instead of HPUX cc and getgr* work fine now.
But I don't understand why.
--
Olivier LACROIX
C.I.R.I.L.
Cellule Réseau StanNet
Chateau du Montet | Tel : +33 3.83.44.74.29
Rue du Doyen Roubault | Fax : +33 3.83.44.02.62
F - 54500 VANDOEUVRE | email : Olivier.Lacroix@ciril.fr
------------------------------
Date: 09 Nov 2000 14:37:44 +0100
From: Julien Quint <julien.quint@xrce.xerox.com>
Subject: Re: Hash assignments in loops?
Message-Id: <thlmutnu53.fsf@lautaret.grenoble.xrce.xerox.com>
gelshocker@my-deja.com writes:
> For some reason I can't seem to populate hashes in a loop block. For
> example, I have a forloop that splits @lines into 2 elements, assigning
> the elements as key/value into a %hash.
A good, perlish way to do it is to use a map, for instance if there are 2
fields per line separated by a comma:
my %h = map { my($k, $v) = split /,/; $k => $v } @lines;
--
Julien
------------------------------
Date: Thu, 9 Nov 2000 11:13:07 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Help -- msgget with key >= 0x80000000 fails
Message-Id: <8ue0on$apu$1@soap.pipex.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn90ku48.22p.mgjv@martien.heliotrope.home...
> Perl actually treats it as a double, and that double gets cast to a
> key_t. If you cast a dbl to an int, I don't think you're guaranteed to
> get a negative number. However, on my Linux box, it does become
> negative, and equal to INT_MIN. Any large value behaves like that. So,
> it looks like your key_t ends up as INT_MIN. It is very well possible
> that that is disallowed. In fact, W. Richard Stevens[1] says
>
> Each IPC structure [..] in the kernel is defined by a nonnegative
> integer identifier.
> [...]
> The data type of this key is the primitive system data type key_t,
> which is often defined as a long integer in the header
> <sys/types.h>.
>
> So, it looks like key_t being a signed type, but only allowing positive
> values is normal behaviour. This means that your key_t should be between
> 0 and INT_MAX (on linux).
The Open Group agrees with you. From
http://www.opengroup.org/onlinepubs/7908799/xsh/ipc.html
- begin quote -
Each individual shared memory segment, message queue and semaphore set is
identified by a unique positive integer, called respectively a shared memory
identifier, shmid, a semaphore identifier, semid, and a message queue
identifier, msqid.
- end quote -
> Anything else is disallowed. Anything between
> 0x0 and 0x7fffffff is allowed. Your key_t is simply too large :)
Now this I dispute. I believe that any reasonably sane person would look at
the above specification and decide that the _correct_ type for key_t is
_unsigned_ int, since there are no valid negative values.
You are right, however, in that perl is not at fault, and that this is no
longer the correct forum for this discussion. Thanks for your help!
Geoff
------------------------------
Date: 9 Nov 2000 11:02:17 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Help -- msgget with key >= 0x80000000 fails
Message-Id: <8ue07p$d0c$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn90ku48.22p.mgjv@martien.heliotrope.home>:
> Perl actually treats it as a double, and that double gets cast to a
> key_t.
[ This is done as key = (key_t)SvNVx(sv). ]
> If you cast a dbl to an int, I don't think you're guaranteed to
> get a negative number. However, on my Linux box, it does become
> negative, and equal to INT_MIN. Any large value behaves like that.
[...]
> We've now established, I hope, that Perl isn't to blame here, and in
> fact it does the right thing. Maybe the discussion is far enough
> offtopic now that it should be taken to comp.unix.programmer
Of course Perl is to blame here. perldoc perlnumber.
Perl should never convert things to an integer type by
(foo_t)SvNVx(sv), since it is *defined* how it should do it... The
are only two problems:
a) is key_t always an integer type?
b) perl should know whether the range of key_t is in the range of IV
or UV (or neither) at compile time, so additional Configure tests
should be created. This may be hard...
Ilya
------------------------------
Date: 09 Nov 2000 06:29:55 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Help with HTML::Parser module
Message-Id: <m3d7g5fkng.fsf@mumonkan.sunstarsys.com>
daniel@chetlin.com (Daniel Chetlin) writes:
> On 8 Nov 2000 12:48:00 -0100,
> Juan Eliseo Carrasco Díaz <eliseo@cocoon.ulpgc.es> wrote:
> >I trying to delete all the <font face="Arial"> and <font face="Times new
> >
> >roman"> marks and its respective </font> marks of my HTML pages, but I
> >can't find an easy way.
> [snip example]
> >Somebody say me that HTML::Parse module can help me. I downloaded it. I
> >read the documentation, but I don't know how to start. (I'm a beginner).
>
> Hopefully you'll take this as a fishing line, not as fish.
>
[...]
>
> Note that this solution doesn't deal perfectly well with nested `font'
> tags -- to do that correctly would require a minor addition of a counter
> to maintain state.
>
Ditto here on the fishing line. See if you can get something like this
to work. (This code will certainly lock up on malformed html :)
#!/usr/bin/perl -wT
{
local $/ = '', my $text = <DATA>; # slurp whole file into $text
my $fontname = "Arial"; # font to remove
while ($text =~ /(.+)<font face="$fontname">(.+)/si) {
my ($prefix, $suffix) = ($1, $2); # greedy prefix
my $counter = 0;
while ( $suffix =~ m{</font>}sgoi ) {
my ($pre, $suf) = ($`, $'); # nongreedy pre
my $cnt = (() = $pre =~ /<font /sgoi); # counts "<font ...>" stanzas
if ($counter == $cnt) {
$suffix = $pre . $suf; # removes corresponding "</font>"
last; # done with inner while loop
} else {
++$counter; # keep looking
}
}
$text = $prefix . $suffix;
}
print $text;
}
__DATA__
<html>
<head><title>Hi</title>
</head>
<body>
this is normal text.
here is <font face="Arial">arial</font>.
<font face="Arial">here are
<font face="Times New Roman">nested fonts</font>.</font>
</body>
</html>
__END__
HTH.
--
Joe Schaefer
------------------------------
Date: Thu, 09 Nov 2000 13:12:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with HTML::Parser module
Message-Id: <vq7l0t0kvvtf2p67cmsr1kcuhipt6fgah8@4ax.com>
Daniel Chetlin wrote:
>Note that this solution doesn't deal perfectly well with nested `font'
>tags -- to do that correctly would require a minor addition of a counter
>to maintain state.
Oh yes. I think in common browsers, "<font>" tags MUST be matched with a
"</font>" tag. That can make life easier.
>You might also take a look at HTML::TokeParser, which comes bundled with
>HTML::Parser. It's a slightly easier interface to get used to, and would
>handle this task quite well.
Yup. Here's code that does it.
<grumble>Note that HTML::TokeParser is not consistent in the format of
the token it returns. For one, it returns the original source text in
the last item of the token (anonymous array), for start and end tags,
and for plain text; but for comments and processing instructions (of
type "<!...>"; it looks to be unaware of "<?...?>" style tags), it
strips of the delimiters! If done properly, a simple
print $t->[-1]
would have sufficed! Now, the code is more elaborate than needed to be.
Besides, HTML comments are really a special case of the "<!..." thing:
"<!" which includes a comment starting with "--" and ending with "--",
and ">" closing the tag. A HTML comment needn't be ALL comment!
And second (but not applicable for this example), there's no good reason
for get_token and get_tag to return a different kind of token.
</grumble>
Anyway, this looks to be working for the example HTML.
my $file = 'test.htm';
use HTML::TokeParser;
my $p = new HTML::TokeParser($file)
or die "Cannot create HTML parser: $!";
my @font; # font tag stack
my %suppress = ( arial => 1, 'times new roman' => 1 );
while(my $t = $p->get_token) {
if($t->[0] eq 'T') {
print $t->[-1]; # print text
} elsif($t->[0] eq 'S' or $t->[0] eq 'E') {
unless($t->[1] eq 'font') {
print $t->[-1]; # print tag
} elsif($t->[0] eq 'S') {
if($t->[2]{face} && $suppress{lc $t->[2]{face}}) {
push @font, 0; # suppressed
} else {
# passed along
print $t->[-1];
push @font, 1;
}
} else { # </font>
# print only if opening tag wasn't suppressed
pop @font and print $t->[-1];
}
} elsif($t->[0] eq 'C') { # comment
print "<!--$t->[1]-->"
} elsif($t->[0] eq 'D') { # <!DOCTYPE ...>
print "<!$t->[1]>"
}
}
--
Bart.
------------------------------
Date: 09 Nov 2000 14:53:51 +0100
From: Julien Quint <julien.quint@xrce.xerox.com>
Subject: Re: Help with HTML::Parser module
Message-Id: <thitpxnte8.fsf@lautaret.grenoble.xrce.xerox.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> Oh yes. I think in common browsers, "<font>" tags MUST be matched with a
> "</font>" tag. That can make life easier.
This is way off-topic but please remember that the FONT tag is evil:
http://www.w3.org/MarkUp/#guidelines
--
Julien
------------------------------
Date: 09 Nov 2000 08:57:41 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Help with HTML::Parser module
Message-Id: <m38zqtfdt6.fsf@mumonkan.sunstarsys.com>
Julien Quint <julien.quint@xrce.xerox.com> writes:
> This is way off-topic but please remember that the FONT tag is evil:
>
> http://www.w3.org/MarkUp/#guidelines
Thus the need to remove them ;)
--
Joe Schaefer
------------------------------
Date: Thu, 9 Nov 2000 11:08:37 -0000
From: "Alan Dougall (ntl)" <abaltd@ntlworld.com>
Subject: how do I process multiple selections?
Message-Id: <wCvO5.88231$hk2.280518@news6-win.server.ntlworld.com>
I am trying to ensure that multiple selections on a form are recorded ok.
My Perl script uses a form with method=POST but I am only picking up the
first selected value in the selection options list (and I don't want to use
radio buttons).
I presume that here is a '&' delimiter (?) between the two selected values
being confused as a parameter delimiter.
How do I distinguish these, or "escape" it in the form processing?
I am saving the parameters in a standard fashion, and I don't know which of
these parameters may be defined as a multiple selection:
@stuff = $q->param;
foreach $stuff (@stuff) {
${$stuff} = $q->param($stuff);
${$stuff} =~ s/\'//g;
}
Any tips?
--
Alan Dougall
alan.dougall@virgin.net
http://start.at/the.cross
------------------------------
Date: Thu, 9 Nov 2000 23:39:40 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how do I process multiple selections?
Message-Id: <slrn90l6ob.22p.mgjv@martien.heliotrope.home>
On Thu, 9 Nov 2000 11:08:37 -0000,
Alan Dougall (ntl) <abaltd@ntlworld.com> wrote:
> I am trying to ensure that multiple selections on a form are recorded ok.
> My Perl script uses a form with method=POST but I am only picking up the
> first selected value in the selection options list (and I don't want to use
> radio buttons).
You never mention it, but are you using CGI.pm? Your code looks like you
might, but you never know. If you aren't, you probably should.
> @stuff = $q->param;
That looks like CGI.pm to me.
> foreach $stuff (@stuff) {
> ${$stuff} = $q->param($stuff);
> ${$stuff} =~ s/\'//g;
What are you doing here? Or rather, what are you trying to do here? Are
you using symbolic references to set globals? Why? Why would you do
that, when you already have access to all these things by directly
calling param?
> }
Assuming it is indeed CGI.pm.
# man CGI
[snip]
FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:
@values = $query->param('foo');
-or-
$value = $query->param('foo');
Pass the param() method a single argument to fetch the
value of the named parameter. If the parameter is multi
valued (e.g. from multiple selections in a scrolling
list), you can ask to receive an array. Otherwise the
method will return a single value.
If a value is not given in the query string, as in the
queries "name1=&name2=" or "name1&name2", it will be
returned as an empty string. This feature is new in 2.63.
[snip]
If I were you, I would try something like:
@stuff = $q->param('whatever_the_name_of_the_parameter_is');
you are doing the evil
${$stuff} = $q->param($stuff};
which is always a scalar. And a global one for that. A scalar cannot
hold multiple values. Just one.
Martien
--
Martien Verbruggen |
Interactive Media Division | life ain't fair, but the root
Commercial Dynamics Pty. Ltd. | password helps. -- BOFH
NSW, Australia |
------------------------------
Date: 09 Nov 2000 12:49:42 +0000
From: nobull@mail.com
Subject: Re: how do I process multiple selections?
Message-Id: <u9r94lb995.fsf@wcl-l.bham.ac.uk>
"Alan Dougall (ntl)" <abaltd@ntlworld.com> writes:
> I am trying to ensure that multiple selections on a form are recorded ok.
> My Perl script uses a form with method=POST but I am only picking up the
> first selected value in the selection options list (and I don't want to use
> radio buttons).
The CGI param() method called in a scalar context returns only the
first selection. In a list context it returns all selections.
> I am saving the parameters in a standard fashion,
Where "standard fashion" is a euphamism for "each in a selarate
package scalar variable in the current package using symbolic
references".
> @stuff = $q->param;
> foreach $stuff (@stuff) {
> ${$stuff} = $q->param($stuff);
> ${$stuff} =~ s/\'//g;
> }
If you want to be able to store multiple values you'll have to store
them in a fashion that accomodates multiple values. You can do this
by storing in an array, in the keys of a hash or in a scalar using the
join() function to convert the list of values into a delimited string.
If you don't want massive debugging and security problems then ditch
the symbolic references and use a single hash. If you really want
separate variables for each parameter then at the very least use a
separate namespace (package).
For example:
my @stuff = $q->param;
foreach my $stuff (@stuff) {
s/\'//g for @{"Stuff::$stuff"} = $q->param($stuff); # In package Stuff::
s/\'//g for @{$stuff{$stuff}} = $q->param($stuff); # In hash %stuff
}
> Any tips?
You may want to take a look at the import_names() and Vars() methods
in CGI.pm since off-the-shelf solutions are usually preferable to
wheel-reinvention.
You should also get into the habit of using my() to limit the scope of
all temporary variables to the block of code where the are used.
Putting "use strict" will tell Perl to throw an exception you when
you've forgotten[1] my() or used a symbolic reference. If you need to
use a sybolic reference then put "no strict 'refs'" in the block where
you use the sybolic reference.
Enabling warnings also helps.
[1] But don't get complacent - it can't tell you when you've put the
my() in too wide a scope.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 9 Nov 2000 13:13:41 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: how do I process multiple selections?
Message-Id: <ant091341d07fNdQ@oakseed.demon.co.uk>
In article <wCvO5.88231$hk2.280518@news6-win.server.ntlworld.com>,
Alan Dougall (ntl) <URL:mailto:abaltd@ntlworld.com> wrote:
>
> I am trying to ensure that multiple selections on a form are recorded ok.
[snip]
> I am saving the parameters in a standard fashion, and I don't know which of
> these parameters may be defined as a multiple selection:
>
> @stuff = $q->param;
> foreach $stuff (@stuff) {
> ${$stuff} = $q->param($stuff);
> ${$stuff} =~ s/\'//g;
> }
I'm not sure that's the best way to start a CGI script - I would
place the expected parameters into scalars or arrays manually. Using
these symbolic references is disallowed by "use strict" and it is
considered safer and generally better style to use strict, so that's
another reason you might wish to avoid them. The third reason not to
use this code is that you are discarding all but the first value of
multiple selections, which is what your question is about.
Multiple selections have one name and potentially more than one value.
In order to get more than one value from CGI's param method you need
to call it in list context. So if your multi-select has the name
'flavours' you would say something like:
my @flavours = $q->param('flavours');
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Thu, 09 Nov 2000 11:52:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: I do not Understand Perl Formats
Message-Id: <4u2l0tgm23c5jqes8c31bk7km9jlb75lsr@4ax.com>
john_s_brown@my-deja.com wrote:
>For example, I have no idea what are all these >>>>> and <<<<<
>characters in the code
">>>" is align to the right. The number of ">" characters is the total
number of characters in the output string (padded with spaces). In the
same way, "<<<" aligns to the left.
>and how can one assign a value to a variable
>found inside a format!
Heh? These are normal, lexical or global, variables.
You don't NEED to use formats. I never do.
First of all, formats are based upon the idea of fixed pitch fonts.
Modern text layout tools are based upon aligning pieces of text,
separated with tabs. So it's the layout program that contains the
intelligence on the text alignment, not your script.
And second, sprintf with "%-10s" or "%10s" as a template, can have the
same effect.
The only bonus you get with formats, is that it can do line wrapping for
you. But it ain't much of a bonus, because you must specify, in the
format, how many lines you want.
format =
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
^<<<<<<<<<<<<<
$x
.
$x = "The only bonus you get with formats, is that it can do line " .
"wrapping for you.";
write;
-->
The only bonus
you get with
formats, is
that it can do
line wrapping
for you.
--
Bart.
------------------------------
Date: Thu, 09 Nov 2000 14:48:16 +0100
From: Damir Boraska <damir.boraska@hrt.hr>
Subject: Last 128 bytes of xxx files?
Message-Id: <3A0AAB20.9A9ABF8A@hrt.hr>
... what is the most EFFICIENT way, how to read dozens
of files (which are binaries, mp3's - more precisely)
...but just last 128 bytes of eacf file? (ID3 tag), without
the need to scan through the whole file?
Thanx for aqny help, I'd appreciate also being put in Cc :-)
------------------------------
Date: Thu, 09 Nov 2000 13:22:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Need Help with a Regular Expression
Message-Id: <k89l0t4sfvpmo2tubg0sic7ln26ski0udu@4ax.com>
medi@cybershell.com wrote:
> $v =~ m/($GramInt)|($GramString)|($GramFloat)|($GramHex)/;
You should test for $GramFloat before attempting to test for $GramInt.
> $v =~ m/($GramFloat)|($GramInt)|($GramString)|($GramHex)/;
--
Bart.
------------------------------
Date: Thu, 09 Nov 2000 12:30:04 -0000
From: <vidulats@yahoo.co.uk>
Subject: Passing Reference
Message-Id: <t0l66ck153gs27@corp.supernews.com>
Hello,
In my PL file I'm passing a reference to a function like:
testarray(\$y);
In the XS file, my function is:
testscalar(sc_ref)
SV * sc_ref
CODE:
{
SV * j;
char * val;
int m;
j=SvRV(sc_ref);
val=(char *)SvPV(j, PL_na);
printf("Address = %u, Value = %s\n",j, val);
val++;
printf("Address = %u, Value = %s\n",j, val);
}
OUTPUT:
sc_ref
If I change the contents of "val", I want same changes to be reflacted
back to the PL file.
Instead of Passing a reference, if I pass the variable name, testscalar
($y) then I'm getting the reflected values in my PL file.
void
testscalar(sc)
char * sc
CODE:
{
printf ("Address = %u, Value = %s\n", &sc, sc);
sc++;
printf ("Address = %u, Value = %s\n", &sc, sc);
}
OUTPUT:
sc
Anyone guide me,
Thanks in advance,
Regards,
Vidula
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Thu, 09 Nov 2000 12:28:05 GMT
From: Morpheus <incubus@hawaii.rr.com>
Subject: Perl Registry Entries hosed?
Message-Id: <me5l0t0kitj80eoc7risn651p1rhrivndd@4ax.com>
Hello all. I have Apache 1.3.14 running on a Win98SE machine and have
been having problems getting cgi scripts to run through my browser.
Basically it tells me that I don't have permission to run the script.
I chalked it off to not being able to change the permissions and
resolved myself to find a workaround. Several hours later and still
nothing in sight, I decided to check my registry entries for perl
since I couldn't even run a script in DOS or a perl window. The
results I found here are disturbing to me, but since I am new to Perl,
I thought I'd share this with the experts and get your opinion.
Sorry for the length of the second key, it really is that long.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Components\CEA5F934EA793D118A360001A54077F3
key: C?\usr\bin\Perl56.dll
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Features\471C3F0EC1F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eAwAy0lA$np?aM&g(`*[eAwAy0lB$np?aM&g(`*[eAwAy0lC$np?aM&g(`*[eAwAy0lD$np?aM&g(`*[eAwAy0lE$np?aM&g(`*[eAwAy0lF$np?aM&g(`*[eAwAy0lG$np?aM&g(`*[eAwAy0lH$np?aM&g(`*[eAwAy0lI$np?aM&g(`*[eAwAy0lJ$np?aM&g(`*[eAwAy0lL$np?aM&g(`*[eAwAy0lRXGg9S+!g(D700(99lI8TXGg9S+!g(D700(99lI8UXGg9S+!g(D700(99lI8VXGg9S+!g(D700(99lI8M$np?aM&g(`*[eAwAy0lYXGg9S+!g(D700(99lI8
ActivePerl
Is this right or is my ActivePerl 5.6.0.620 installation hosed? The ?
in the path in the first key I'm sure is whacked, but then again, I am
new to this. There were other keys in the same folder as the second
key, and they were similar in length, just a bunch of numbers, symbols
and letters. I tried setting the path using set
path=%path%;c:\usr\bin but it returned an error about a backslash near
usr\ or something like that.
Any help would be appreciated. I am expecting to have to reinstall
Perl, but want to verify before doing this again.
Thanks!
James
------------------------------
Date: Thu, 9 Nov 2000 07:43:34 -0600
From: "preetham" <preetham@india.hp.com>
Subject: Re: Perl vs. ActivePerl (newbie)
Message-Id: <8ue9n9$r6r$1@web1.cup.hp.com>
"Kurt Stephens" <kstep@pepsdesign.com> wrote in message
news:8uc4fm$p37$1@slb0.atl.mindspring.net...
> NT, ActiveState is the way to go. Most of the (Unix vs NT) compatibility
> issues have been fixed, and without a C compiler, this is about the only
way
> to get some modules to install.
I agree with that
As far as limitations go, there are many
> modules available on CPAN that do not have PPM-installable packages
> available. As you are just getting started with Perl, you can probably
get
> along without Damian Conway's Parse::RecDescent for a while ;).
>
If u have make and gunzip for windows (u can download it easily) u can still
install the packages. but the HTML documentation is not generated. u can
still use perldoc
------------------------------
Date: Thu, 9 Nov 2000 12:36:46 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Pushing a hash on to a stack...
Message-Id: <ant091246868fNdQ@oakseed.demon.co.uk>
In article <8FE79953FCraznar@24.192.1.17>, Christopher Burke
<URL:mailto:craznar@hotmail.com> wrote:
>
> Thats right - I will not bother this newsgroup anymore,
> after all there is no help for people new to Perl only
> experts are welcome here.
I'm no expert, having only used Perl for a few months, but I have felt
very welcome here despite making mistakes, and sometimes holding fixed
views that turn out to be incorrect. I have probably learnt more from
this group than I have from day to day Perl coding.
If people spot what they think is a misunderstanding on your part and
try to guide you in the right direction, you should welcome it and try
to help them help you by being as open as possible about what you
think you know. If you regard people's questioning of your understanding
as a personal attack and get all defensive, then you will miss out on
the benefit of other's experience.
I think this group is the best Perl resource you could wish for.
I'm a Usenet fan anyway, but this group is one of the best I've ever
subscribed to. I think you need to relax and open up a bit.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Thu, 09 Nov 2000 11:06:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: reconstituting hash from reference?
Message-Id: <5p0l0t8ooqf6br0739i0insrsujkijq6kr@4ax.com>
Chris wrote:
>I have a deep nest of subroutines. At various calling depths I need to
>use and modify some data from the top level. Rather than create globals
>or a bloated (and error-prone) list of arguments for each subroutine, I
>decided to create a hash in the top-level element and pass it down. Now I
>want to create a hash data element and pass a reference to it via the same
>mechanism.
I think you mean something like this?
foo($data{nest});
use Data::Dumper;
print Dumper \%data;
sub foo {
for my $hash (shift) {
$hash->{key} = 'value';
}
}
-->
$VAR1 = {
'nest' => {
'key' => 'value'
}
};
Gee, it works. I hadn't really expected that.
It can work, because thanks to the for "loop", the lexical variable
$hash is an alias to the original hash element, even if it wasn't
defined yet; so using it as a hash reference triggers autovivification.
If you don't want to use the aliasing (after all, it's a weird syntax),
you must make sure you do pass a hash reference, which means,
initializing it if it doesn't exist yet.
foo($data{nest} ||= {}); # make sure it's initialized
use Data::Dumper;
print Dumper \%data;
sub foo {
my $hash = shift; # not an alias, but a reference
# to the same structure
$hash->{key} = 'value';
}
--
Bart.
------------------------------
Date: Thu, 09 Nov 2000 07:02:26 -0500
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: reconstituting hash from reference?
Message-Id: <3A0A9251.F8825682@cc.gatech.edu>
Chris wrote:
> I have a deep nest of subroutines. At various calling depths I need to
> use and modify some data from the top level. Rather than create globals
> or a bloated (and error-prone) list of arguments for each subroutine, I
> decided to create a hash in the top-level element and pass it down. Now I
> want to create a hash data element and pass a reference to it via the same
> mechanism.
>
> I have no problem passing the new hash inside the old using:
> $data{"stuff"} = \%stuff;
> and can access the data using
> ${$data{"stuff"}}{key} = value;
> but this is an awkward notation to use all the time.
$data{"stuff"}->{key} = value;
OR
$data{"stuff"}{key} = value;
> I can extract the
> reference to a scalar using:
> my $stuff_ref = $data{"stuff"};
> and then access the data using
> ${$stuff_ref}{key} = value;
> or
> $$stuff_ref{key} = value;
> but that's only marginally better.
>
use
$stuff_ref->{key} = value;
>
> I thought I might get away with
> %hash = $hashref;
> but that doesn't work.
>
use
%hash = %$hashref;
>
> I read the perllol and perldsc pages but can't see any way to recreate the
> original data as a "normal" hash....
>
> What am I missing?
Read perlref. All the reference syntax is explained there.
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Thu, 09 Nov 2000 14:38:53 +0100
From: Damir Boraska <damir.boraska@hrt.hr>
Subject: Re: strip html tags from string $text
Message-Id: <3A0AA8ED.55B6B0F5@hrt.hr>
Instead of writing useless sentences such as
"go and read the FAQ", you people could have
just written this:
$text =~ s/<.*?>//g;
and actually HELP someone.
Was that such an effort????
dobrocinitelj@my-deja.com wrote:
>
> I have a string $text containing multiple lines of text, how can I
> strip all the html tags?
------------------------------
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 4854
**************************************