[19502] in Perl-Users-Digest
Perl-Users Digest, Issue: 1697 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 5 09:05:26 2001
Date: Wed, 5 Sep 2001 06:05:09 -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: <999695108-v10-i1697@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 5 Sep 2001 Volume: 10 Number: 1697
Today's topics:
doing <a #name="..."> in CGI output <magic@bet.po.opole.pl>
Re: Getting pack results interpreted as unicode. <tinamue@zedat.fu-berlin.de>
Re: Getting pack results interpreted as unicode. (Rafael Garcia-Suarez)
Header error with Activeperl on Win2K Sp2 (Ross)
Re: Help with installing a module, Win32::SerialPort (Helgi Briem)
Re: ignoring lines in file using array of phrases to sk (Mike Solomon)
Re: Open 2 exes from Perl (Chris Harris)
Problem with Storable, and large datsets (Stan Brown)
Re: Problems writing to a file that already exists! <Pcmann1@btinternet.com>
Re: Recommendations for a PERL editor <tinamue@zedat.fu-berlin.de>
Re: require and mod_perl <bart.lateur@skynet.be>
Re: require and mod_perl nobull@mail.com
Re: Shell Scripts vs. Perl Scripts <krahnj@acm.org>
Small Program - Delete douplicates in list (Greg Coffman)
Re: Small Program - Delete douplicates in list nobull@mail.com
Re: Small Program - Delete douplicates in list <krahnj@acm.org>
Re: Small Program - Delete douplicates in list <J1@acmecity.com>
tr/// Problem (Donald Crowhurst)
Re: tr/// Problem (Rafael Garcia-Suarez)
Re: tr/// Problem (Ronald Blaschke)
Re: tr/// Problem <krahnj@acm.org>
Re: Undef'ing multiple variables <tinamue@zedat.fu-berlin.de>
Re: Undef'ing multiple variables <tinamue@zedat.fu-berlin.de>
Re: Undef'ing multiple variables (Rafael Garcia-Suarez)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 4 Sep 2001 16:42:01 +0200
From: Lukasz Wiechec <magic@bet.po.opole.pl>
Subject: doing <a #name="..."> in CGI output
Message-Id: <p7p2n9.vkk.ln@blacky.wbk.com>
Hello, folks !
I have the following question: I use CGI module to produce dynamically
generated HTML pages with some data from database. The data processing
takes some time, and I want to include little "table of contents"
near the top of the page. each element of TOC is like that:
<a href="#point1">...</a>
<a href="#poing2">...</a> etc.
Below, sections start with:
<a name="point1"></a>
....
<a name="point2"></a> and so on.
The problem is that when I click on the link in TOC, the CGI script gets
executed again. How can I avoid that ?
Greetings from Poland,
--
Milego dnia,
Lukasz Wiechec
------------------------------
Date: 5 Sep 2001 10:36:04 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Getting pack results interpreted as unicode.
Message-Id: <9n4v6k$5boqn$3@fu-berlin.de>
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Benjamin Goldberg wrote in comp.lang.perl.misc:
> } Both strings created with v<digits> and pack U, <digits> print out the
> } same, but they clearly aren't the same internally:
> [ ... ]
> } $ perl -e 'printf "%vd", pack U, 2147483647'
> } 253.191.191.191.191.191
> What perl version are you using ? I can't reproduce this.
i've got
This is perl, v5.6.0 built for i586-linux
> } What does printf see that I don't?
> Have you tried Devel::Peek ?
perl -MDevel::Peek -wle'
$x= v2147483647;$y=pack U, 2147483647;
Dump $x;Dump $y;
print "$x,$y"'
SV = PV(0x80f3bac) at 0x810ad60
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x8104190 "\375\277\277\277\277\277"\0
CUR = 6
LEN = 7
SV = PV(0x80f3c6c) at 0x8108a60
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x80f9130 "\375\277\277\277\277\277"\0
CUR = 6
LEN = 7
ý¿¿¿¿¿,ý¿¿¿¿¿
so it's the utf8 flag...
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 5 Sep 2001 11:04:35 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Getting pack results interpreted as unicode.
Message-Id: <slrn9pc1mb.bc.rgarciasuarez@rafael.kazibao.net>
Tina Mueller wrote in comp.lang.perl.misc:
}
} perl -MDevel::Peek -wle'
} $x= v2147483647;$y=pack U, 2147483647;
} Dump $x;Dump $y;
} print "$x,$y"'
} SV = PV(0x80f3bac) at 0x810ad60
} REFCNT = 1
} FLAGS = (POK,pPOK,UTF8)
} PV = 0x8104190 "\375\277\277\277\277\277"\0
} CUR = 6
} LEN = 7
} SV = PV(0x80f3c6c) at 0x8108a60
} REFCNT = 1
} FLAGS = (POK,pPOK)
} PV = 0x80f9130 "\375\277\277\277\277\277"\0
} CUR = 6
} LEN = 7
} ý¿¿¿¿¿,ý¿¿¿¿¿
}
} so it's the utf8 flag...
With perl 5.6.1 (or later), both $x and $y have UTF8 set.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 5 Sep 2001 03:45:40 -0700
From: stimpy_j_cat@hotmail.com (Ross)
Subject: Header error with Activeperl on Win2K Sp2
Message-Id: <e2d756e7.0109050245.1a5b8b46@posting.google.com>
Hi,
I have written a small client web app to demonstrate the multiplatform
capabilities of SOAP in Perl and I'm getting the following error
message which seems unrelated to any code I have written:
"CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers it did return are:"
The .pl file works fine from the command line but when viewed in a
browser displays the following error and only renders half of the
remaining page.
I installed Active Perl on my workstation solely for this demo so this
is the first and only time I have found out about this problem. Can
anyone suggest why I should be getting this error?
TIA,
Ross.
------------------------------
Date: Wed, 05 Sep 2001 10:20:29 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Help with installing a module, Win32::SerialPort
Message-Id: <3b95fb12.582546076@news.isholf.is>
On Tue, 04 Sep 2001 18:41:05 +0100, Nial Stewart
<nials@britain.agilent.com> wrote:
>Dan Nunn wrote:
>>
>> "Nial Stewart" <nials@britain.agilent.com> wrote in message
>> news:3B94DC06.EFD0B384@britain.agilent.com...
>>
>> > "Can't locate Win32:API.pm in @INC (@INC contains "
>>
>> > Can anyone tell me what's going wrong?
>>
>> You need to install the Win32::API module. Get it at this URL, then in DOS,
>> type 'ppm install Win32-API.ppd' to install it:
>> http://www.activestate.com/PPMPackages/5.6plus/Win32-API.ppd
>
>
>I've tried doing what David suggested above. Initially I got the
>message
>
>"Installing package 'Win32-API.ppd'..."
>
>but then got
>
>"Error installing package 'Win32-API.ppd':Error reading...
>..(path to file Win32-API.tar.gz at www.activestate.com)"
You probably lack a path to your proxy server.
This is the cause of 90% of PPM failures (10%
are failures to spell package names correctly,
case and all).
Set your environment variable
HTTP_proxy to http://yourproxy.domain.foo:PORT
or whatever it happens to be at your site.
Get a command line.
Install the old Win32::API package (the new
and improved package that comes with Activeperl
is Win32API in one word). You do this by typing
ppm install Win32-API
Your Win32::SerialPort installation should
now go smoothly. Note that including an
install.pl script is non standard (but I suppose
as good a method as any).
Regards,
Helgi Briem
------------------------------
Date: 5 Sep 2001 05:29:06 -0700
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Re: ignoring lines in file using array of phrases to skip
Message-Id: <56568be5.0109050429.48d906e9@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9p9lo5.qbl.tadmc@tadmc26.august.net>...
> Mike Solomon <mike_solomon@lineone.net> wrote:
>
> >What I can't work out how to do is put end of line character ($) into
> >the array and make it work
>
Thanks for the help with this.
I have a question about your answer
[snip]
> ^^
>
> >while (<FILE>) {
> > chomp;
> > $line = $_;
>
>
> Why copy it to $line?
>
> Either use $_:
>
> print if $_ !~ /$ignore/i;
> or
> print unless /$ignore/i;
>
> or put the value directly into $line:
>
>
> while ( $line = <FILE> ) {
>
>
> > print if $line !~ /$ignore/i;
>
>
> print unless $line =~ /^kernel: ($ignore)$/i; # factored out 1st 8 chars
If I use the format
while ($line = <FILE)
and I am using strict I will have to declare $line first, in other words
my ($line);
while ($line = <FILE)
Why is this better than using
while (<FILE>) {
my $line = $_;
Thanks
Regards
Mike Solomon
------------------------------
Date: Wed, 05 Sep 2001 12:12:00 GMT
From: clh8762@hotmail.com (Chris Harris)
Subject: Re: Open 2 exes from Perl
Message-Id: <3b96162c.84445530@news.networktel.net>
On Wed, 05 Sep 2001 08:38:13 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:
>Helgi Briem wrote:
>
>>To summarise, there are three ways:
>>
>>system ('start notepad')
>>system(1, 'notepad');
>>use Win32::Process;
>
>Four. There's the ShellExecute API call, through Win32::API.
>
>--
> Bart.
Here is another way.
use Win32;
my $App = "c:\\windows\\notepad.exe";
my $Args = "notepad e:\\perl\\temp.txt";
if(Win32::Spawn( $App, $Args, $Pid ))
{
print "$App was successfully created with PID $Pid \n";
}
hth,
Chris
------------------------------
Date: 5 Sep 2001 07:44:43 -0400
From: stanb@panix.com (Stan Brown)
Subject: Problem with Storable, and large datsets
Message-Id: <9n537b$g7k$1@panix3.panix.com>
I have a perlTK script which fetches (potentialy large) datasets ( 1
million rows +) from an Oracle database. I know that this works since with
the script as a single process, I was able to retrieve these large data
sets.
I have just modified this to work in a parent -> child way. The chiild
does the actual DBI fetch, and pases the results to the parent using
Storable. Like this:
# Prepare query
$sths = $dbh->prepare("$stmt");
$rc = $sths->execute or die $DBI::errstr;
$records_array_ref = $sths->fetchall_arrayref();
print_debug(1, "Fetch done\n",1,0);
store_fd $records_array_ref, $writer ||
die "can't store to $writer\n";
And the parent retrieves this dataaset like this:
$records_array_ref = fd_retrieve $reader;
This works fine for small data sets.
However when I run it againsta a large dataset, here is what I see.
Watching the processes using HP' glance+ (sort of a glorifed top). I see
the chile grow to have a resident set size of about 1.4G. At this point in
time, the parent is tiny. I assume that at this point in time the child has
finished the fetch, and starts sending the data. Then the child actually
starts shrinking, as the parent grwas. I would axpect this, as the data is
passed from parent to child. So far, all looks well, However sometime after
taht it dies with the following error:
Corrupted storable file (binary v2.4) at blib/lib/Storable.pm (autosplit
into blib/lib/auto/Storable/fd_retrieve.al) line 328, at ./foo.pl line 2338
my suspicion is that Storable is having problems with large (> 1G ?)
datsets. Is it possible thta it has not been compiled with large file
support? Perl has been, and is able to handle files > 1G, as evidenced by
other scripts I am using.
Platform os HP-UX 10.20 (32 bit).
What can I do to fix this?
------------------------------
Date: Wed, 5 Sep 2001 13:07:57 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Re: Problems writing to a file that already exists!
Message-Id: <9n54fs$n68$1@neptunium.btinternet.com>
Thanks both of you for the excellent suggestions!
I've tried the one Tad suggested, and it now works!
Thanks again both of you!
Regards
- Pete
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9pahbe.s4u.tadmc@tadmc26.august.net...
> Peter Mann <Pcmann1@btinternet.com> wrote:
>
> >I am having difficulties writing to a file that already exists.
>
>
> I do not see you attempting to do any writing below.
>
> You are having difficulties with _opening_ a file, not with
> writing to a file.
>
>
> >From the
> >books I have read relating to this problem, I can't determine the most
> >suitable option to specifiy in the code extract below.
>
>
> What books do you have? Titles please.
>
>
> >For instance, I have opened the file for write only, and if it doesn't
exist
> >then create it. However, when the file does already exist (i.e.
report.htm),
> >it should delete it and create a new one.
>
>
> Why?
>
> Why can't it just delete the file's _contents_ and reuse the same inode?
>
> If you really want a _new_ file (different inode), then you can
> just unlink() and ignore the return value before your open().
> (which will still be a "race", see below)
>
>
> >But there doesn't appear
>
>
> Where have you looked?
>
>
> >to be a
> >suitable 'option' to delete if already exists. Can someone please advise
me
> >if there is a simple option to do this.
>
>
> Have you tried looking on your very own hard drive yet?
> (rhetorical question, we can see that you didn't, else
> you would already have your answer :-)
>
> perldoc -q open
>
> "How come when I open a file read-write it wipes it out?"
>
>
> Hey! You _want_ it to wipe out the file. Maybe you should
> read that Frequently Asked Question's answer:
>
> --------------------------
> ...
> To open file for writing, create new file if needed or
> else truncate old file:
>
> open(FH, "> $path") || die $!;
> sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT) || die $!;
> sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT, 0666) || die $!;
> --------------------------
>
> try O_TRUNC.
>
> Use the docs Luke.
>
>
> >The only other way I can think of is
> >to check if the file exists, and if it does delete it before creating a
new
> >one. But this appears clumsy coding style.
>
>
> It is far far worse than merely a "style issue". You have described
> what is called a "race condition" where data can become corrupted
> in multitasking environments (such as CGI stuff).
>
>
> >Any suggestions would be much appreciated.
>
> Please check the Perl FAQs *before* posting to the Perl newsgroup.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: 5 Sep 2001 10:52:53 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Recommendations for a PERL editor
Message-Id: <9n5065$5boqn$4@fu-berlin.de>
Tad McClellan <tadmc@augustmail.com> wrote:
> Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
>>Tad McClellan <tadmc@augustmail.com> wrote:
>>
>>> With "#!/usr/bin/perl -w\r\n", step 1 works fine (it stops
>>> at whitespace), and step 2 passes "-w\r" as an argument to perl,
>>> and _perl_ Does The Right Thing.
>>
>>wouldn't it be clever if webserver-admins, ISPs just create
>>a "/usr/bin/perl\r" binary additionally? they would never
> ^^^^^
> Until the program also contained a here-doc, which would also mess up :-)
why? it works for me...
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Wed, 05 Sep 2001 12:50:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: require and mod_perl
Message-Id: <3q7cpto71airdvs794l4nkn1l2fsj02ce4@4ax.com>
peter pilsl wrote:
>Now, in a thread on comp.lang.perl.modules I was told that this structure
>makes the whole thing unrelieable, cause it ends up in using old
>perl4-style libraries. To tell the truth, I dont understand what this
>exactely means and I wonder if my scheme is something to be concerned about
>or not.
In se, I find nothing wrong with perl4-style libraries, if the libraries
themselves are alright.
--
Bart.
------------------------------
Date: 05 Sep 2001 12:53:45 +0100
From: nobull@mail.com
Subject: Re: require and mod_perl
Message-Id: <u9d755izd6.fsf@wcl-l.bham.ac.uk>
peter pilsl <pilsl_@goldfisch.at> writes:
> My mod_perl-scripts all follows the following scheme:
>
> --main.pl---
> use module;
> require './main.lib.pl'
>
> run();
>
> --main.lib.pl
> sub run
> {
> module_sub1();
> module_sub2();
> sub1();
> sub2();
> module_sub3();
> }
> sub1 { ...};
> sub2 { ...};
>
>
> I use this scheme to avoid the 'nested subroutine'-problems as recommended
> in mod_perl doc at
> http://perl.apache.org/guide/porting.html#The_First_Mystery
Personally I recon changing a handfull of file-scoped my()s to our()s
is less hassle.
To check you've got'em all:
( echo -n "sub foobar {"; cat main.pl; echo -n "}" ) | perl -wc
> Now, in a thread on comp.lang.perl.modules I was told
Please do not hop around like this - you've already asked for an
explaination in the other thread so give us a chance to answer there
before starting a new thread.
> that this structure makes the whole thing unrelieable, cause it ends
> up in using old perl4-style libraries. To tell the truth, I dont
> understand what this exactely means and I wonder if my scheme is
> something to be concerned about or not.
Your file main.lib.pl is a Perl4-style library. In other words it
does not have its own package name or import() method like a module
does. A Perl4-style library simply defines subroutines (and other
symbols) directly into whatever namespace is current the _first_ time
it is require()d. So long as main.pl is the _only_ thing to ever
require('./main.lib.pl') then this is not problem. Be aware that this
is true even if you have two scripts[1] that execute the statement
require('./main.lib.pl') in different directories. Only whichever one
happens to be executed first by any particular server process will
load main.lib.pl.
[1] When I say 'scripts' I do, of course, mean 'scripts loaded under
mod_perl and Apache::Registry and which are therefore, in effect,
modules'.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 05 Sep 2001 10:04:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <3B95F907.91B9828A@acm.org>
Heiko Wolf wrote:
>
> > >I want to execute a bs script from a perl script.
> > ^^
> >
> > Eh? Did you mean "bash" instead?
>
> No sorry, I meant "sh" -> UNIX-newbie *plonk*
sh is the Bourne shell, bash is the Bourne again shell, an enhanced
version of the Bourne shell.
> > >How can I do this? Is there a kind of "run"-command?
> >
> > perldoc -f system
> > perldoc -f qx
> > perldoc -q external
> >
>
> So I tried to enter those commands at the command line, and I only got
> error messages like the following:
>
> perldoc -f system
>
> Unknown option: f
> perldoc [-h] [-v] [-u] PageName|ModuleName|ProgramName...
> -h Display this help message.
> -t Display pod using pod2text instead of pod2man and nroff.
> -u Display unformatted pod text
> -m Display modules file in its entirety
> -v Verbosely describe what's going on.
> may either give a descriptive name of the page (as in the
>
> [snip]
It looks like you have an older version of perldoc. The -f switch looks
up fuctions in the perlfunc man page and the -q switch looks up
questions in the perlfaq man pages.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 5 Sep 2001 04:01:33 -0700
From: Laocoon@eudoramail.com (Greg Coffman)
Subject: Small Program - Delete douplicates in list
Message-Id: <eb0d2d4f.0109050301.3d79eb49@posting.google.com>
Yesterday i tried to compare a list of stuff which i alrdy had with
stuff i still need. I thought i could write a small script to do this
faster and also for practice.
And i came up with this (formatted for better viewing) :
while ($a=<STDIN> and $a ne "5\n")
{
if($b{"$a"})
{
$b{"$a"}=''
}
else
{
$b{"$a"}=1
}
}print sort keys %b;
Its supposed to delete a list entry if its entered twice but it
doesn't work. Its propably something simple and obvious but i'm still
new (1 month) so help would be greatly appreciated.
Greg
------------------------------
Date: 05 Sep 2001 12:35:54 +0100
From: nobull@mail.com
Subject: Re: Small Program - Delete douplicates in list
Message-Id: <u9g0a1j2ec.fsf@wcl-l.bham.ac.uk>
Laocoon@eudoramail.com (Greg Coffman) writes:
> Yesterday i tried to compare a list of stuff which i alrdy had with
> stuff i still need. I thought i could write a small script to do this
> faster and also for practice.
Personally I'd use grep (that's GNU grep not the Perl grep function)
for this.
> And i came up with this (formatted for better viewing) :
>
> while ($a=<STDIN> and $a ne "5\n")
> {
> if($b{"$a"})
> {
> $b{"$a"}=''
> }
> else
> {
> $b{"$a"}=1
> }
> }print sort keys %b;
>
> Its supposed to delete a list entry if its entered twice but it
> doesn't work.
Setting an entry in a hash to a string of zero length does not delete
the entry from the hash. Even setting an entry in a hash to be truely
undefined (as distinct from an empty string) does not delete the entry
from the hash. To delete from a hash use the delete() function.
When you fix this your script will print in string collation sequence
all lines that appear an odd number of times in the input upto but not
including the first line that reads '5'. Is that what you wanted?
Side note on formatting - omiting the semicolon before a the closing
brace of a block is usually only considered good style if the whole
block is on one line.
> i'm still new (1 month) so help would be greatly appreciated.
Get into good habits now: strict, warnings, meaningful variable names,
error checking and so on an so forth.
Working without the safety devices because you are new is like saying
"I'm new to mountain climbing, so I can't be bothered with all these
ropes and helmets, perhaps once I've climbed a few small mountains
I'll take the time to learn how to use them." The time you spend
recovering from even a few 12ft falls will soon outwiegh the time you
saved by not using the safety devices.
BTW see also:
FAQ: What's wrong with always quoting "$vars"?
FAQ: How can I remove duplicate elements from a list or array?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 05 Sep 2001 12:07:46 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Small Program - Delete douplicates in list
Message-Id: <3B961608.CA8164E6@acm.org>
Greg Coffman wrote:
>
> Yesterday i tried to compare a list of stuff which i alrdy had with
> stuff i still need. I thought i could write a small script to do this
> faster and also for practice.
> And i came up with this (formatted for better viewing) :
This is a Frequently Asked Question. The answer is in the documentation
that comes with Perl.
perldoc -q duplicate
> while ($a=<STDIN> and $a ne "5\n")
> {
while ( <> ) {
next if /^5/;
> if($b{"$a"})
You shouldn't put quotes around a scalar like this. This tests if the
value of $b{"$a"} is true or in other words not equal to 0 or "0" or
undef or "". If you are using a hash then the keys are unique and you
won't have duplicates.
> {
> $b{"$a"}=''
> }
> else
> {
> $b{"$a"}=1
> }
> }print sort keys %b;
>
> Its supposed to delete a list entry if its entered twice but it
> doesn't work. Its propably something simple and obvious but i'm still
> new (1 month) so help would be greatly appreciated.
perldoc -f delete
$ perl -le'%z=(a => 1);$x= "" ;if($z{"$x"}) {$z{"$x"}=""} else
{$z{"$x"}=1} print">$_< >$z{$_}<" for keys %z'
>< >1<
>a< >1<
$ perl -le'%z=(a => 1);$x= 35 ;if($z{"$x"}) {$z{"$x"}=""} else
{$z{"$x"}=1} print">$_< >$z{$_}<" for keys %z'
>a< >1<
>35< >1<
As you can see your test will create the key whether it is true or not.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 5 Sep 2001 14:11:11 +0200
From: Laocoon <J1@acmecity.com>
Subject: Re: Small Program - Delete douplicates in list
Message-Id: <9n54ov$vpp$04$1@news.t-online.com>
Sorry i posted too early i found an entry in the FAQ and fixed it.
Message by Laocoon@eudoramail.com (Greg Coffman) on: 05-Sep-01 4:01:29 AM
>Yesterday i tried to compare a list of stuff which i alrdy had with
>stuff i still need. I thought i could write a small script to do this
>faster and also for practice.
>And i came up with this (formatted for better viewing) :
>
>while ($a=<STDIN> and $a ne "5\n")
> {
> if($b{"$a"})
> {
> $b{"$a"}=''
delete $b{"$a"}
> }
> else
> {
> $b{"$a"}=1
> }
> }print sort keys %b;
>
>Its supposed to delete a list entry if its entered twice but it
>doesn't work. Its propably something simple and obvious but i'm still
>new (1 month) so help would be greatly appreciated.
>
>Greg
>
------------------------------
Date: 5 Sep 2001 04:16:26 -0700
From: lb@postmaster.co.uk (Donald Crowhurst)
Subject: tr/// Problem
Message-Id: <d9f382f6.0109050316.2960ebb8@posting.google.com>
Hi,
I'm having trouble with a couple of TRs.
I'm trying to replace all double quotes (") and backslashes (\) with
the space character ( ) as follows:
tr/"/ /; #strip the quotes out
tr/\/ /; #strip out the backslash
The former seems to work, although it throws out TEXTPAD so that it
doesn't seem to correctly highlight my code in the following lines
(anyone know how to stop this?). The latter doesn't work at all.
What do I need to do? I have looked in PERLDOC, this NG and the
O'Reilly books, but can't see the solution.
Cheers,
Don.
------------------------------
Date: 5 Sep 2001 11:46:37 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: tr/// Problem
Message-Id: <slrn9pc454.1f6.rgarciasuarez@rafael.kazibao.net>
Donald Crowhurst wrote in comp.lang.perl.misc:
}
} I'm trying to replace all double quotes (") and backslashes (\) with
} the space character ( ) as follows:
}
} tr/"/ /; #strip the quotes out
} tr/\/ /; #strip out the backslash
}
} The former seems to work, although it throws out TEXTPAD so that it
} doesn't seem to correctly highlight my code in the following lines
} (anyone know how to stop this?).
Use a better editor ? (vim highlights this correctly.)
} The latter doesn't work at all.
Right, you should escape the backslash by doubling it.
And you can do this with a single statement :
tr/"\\/ /;
} What do I need to do? I have looked in PERLDOC, this NG and the
} O'Reilly books, but can't see the solution.
Look in perlop, single-quoted strings (the same convention applies to
tr///, as documented in perlop/Gory details of parsing quoted
constructs).
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 5 Sep 2001 11:58:06 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: tr/// Problem
Message-Id: <9n540d$4rmv4$1@ID-57488.news.dfncis.de>
On 5 Sep 2001 04:16:26 -0700, Donald Crowhurst <lb@postmaster.co.uk> wrote:
> I'm having trouble with a couple of TRs.
>
> I'm trying to replace all double quotes (") and backslashes (\) with
> the space character ( ) as follows:
>
> tr/"/ /; #strip the quotes out
> tr/\/ /; #strip out the backslash
"\" is an escape character for interpolated text. Use "\\" instead.
#! /usr/bin/perl -w
use strict;
my $a = 'some \ "text"';
print $a, "\n";
$a =~ y/\\"/ /;
print $a, "\n";
$./t.pl
some \ "text"
some text
Note that the escape was not necessary for the assignment to $a.
Single quoted strings are not interpolated.
I like the slashes as delimiter, so I would choose the above code.
However, Perls DWIM allows the following to work as expected:
$a =~ y'\"' ';
Now the delimiter is a single quote, which also states that the string
should not be interpolated.
Unfortunately, this does not apply to the replacement string. Thus, you
can't say:
$a =~ y'\"'"\';
but need to say
$a =~ y'\"'"\\';
to exchange double quotes with backslashes.
Hope this is useful for you.
> The former seems to work, although it throws out TEXTPAD so that it
> doesn't seem to correctly highlight my code in the following lines
> (anyone know how to stop this?). The latter doesn't work at all.
>
> What do I need to do? I have looked in PERLDOC, this NG and the
> O'Reilly books, but can't see the solution.
--
------------------------------
Date: Wed, 05 Sep 2001 12:12:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: tr/// Problem
Message-Id: <3B961717.EAC861A9@acm.org>
Donald Crowhurst wrote:
>
> I'm having trouble with a couple of TRs.
>
> I'm trying to replace all double quotes (") and backslashes (\) with
> the space character ( ) as follows:
>
> tr/"/ /; #strip the quotes out
> tr/\/ /; #strip out the backslash
>
> The former seems to work, although it throws out TEXTPAD so that it
> doesn't seem to correctly highlight my code in the following lines
> (anyone know how to stop this?). The latter doesn't work at all.
>
> What do I need to do? I have looked in PERLDOC, this NG and the
> O'Reilly books, but can't see the solution.
The backslash has to be escaped (with a backslash).
$ perl -le '$_ = q(test\test"test); print; tr/\\"/ /; print'
test\test"test
test test test
John
--
use Perl;
program
fulfillment
------------------------------
Date: 5 Sep 2001 10:30:49 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4usp$5boqn$2@fu-berlin.de>
Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
> aL <nobody@nowhere.com> wrote:
>> My 2 Questions are:
>> 1) Is there another way I can undef multiple scalars / arrays / hashes at
>> once under the newer versions of Perl without having to add undef functins
>> for EVERY variable I want to undef?
> you could do:
> ($scalar, @array, %hash) = ();
ok, looking at rafael's solution, i noticed that mine
doesn't really undef the @array and %hash, but normally
that shouldn't matter if you just want do delete all content.
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 5 Sep 2001 11:07:18 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n5116$5boqn$5@fu-berlin.de>
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> aL wrote in comp.lang.perl.misc:
> } 1) Is there another way I can undef multiple scalars / arrays / hashes at
> } once under the newer versions of Perl without having to add undef functins
> } for EVERY variable I want to undef?
> OK, I've got a solution that works :
> #!/usr/local/bin/perl -wl
> $s = 1;
> @a = qw/foo bar/;
> %h = ( a => 1, b => 2 );
> print defined $s ? 'def' : 'undef';
> print defined @a ? 'def' : 'undef';
> print defined %h ? 'def' : 'undef';
> eval "undef $_" for qw/$s @a %h/;
> print defined $s ? 'def' : 'undef';
> print defined @a ? 'def' : 'undef';
> print defined %h ? 'def' : 'undef';
hm, i just tried your version with strict and so i declared
all variables with my(). now i'm getting
defined(@array) is deprecated at -e line 6.
(Maybe you should just omit the defined()?)
defined(%hash) is deprecated at -e line 7.
(Maybe you should just omit the defined()?)
so i guess
($s,@a,%h)=();
should be ok.
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 5 Sep 2001 11:40:49 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Undef'ing multiple variables
Message-Id: <slrn9pc3q8.1f6.rgarciasuarez@rafael.kazibao.net>
Tina Mueller wrote in comp.lang.perl.misc:
}
} hm, i just tried your version with strict and so i declared
} all variables with my(). now i'm getting
} defined(@array) is deprecated at -e line 6.
} (Maybe you should just omit the defined()?)
} defined(%hash) is deprecated at -e line 7.
} (Maybe you should just omit the defined()?)
}
} so i guess
} ($s,@a,%h)=();
} should be ok.
There's no difference at the Perl level. Your solution has the advantage
over other solutions that $#a becomes -1.
And I had forgotten that the internal difference should now be
considered accidental and undocumented ;-(
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
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 1697
***************************************