[19925] in Perl-Users-Digest
Perl-Users Digest, Issue: 2120 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 13 03:05:45 2001
Date: Tue, 13 Nov 2001 00:05:10 -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: <1005638710-v10-i2120@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Nov 2001 Volume: 10 Number: 2120
Today's topics:
[Q] Using index in Associate Arrary <infowell@kisdi.re.kr>
Re: [Q] Using index in Associate Arrary <mgjv@tradingpost.com.au>
Re: Can I make one perl cgi script work both in linux a (David Efflandt)
Re: comp.lang.perl <whataman@home.com>
Re: comp.lang.perl <godzilla@stomp.stomp.tokyo>
Re: How to use Shift and GetOpts <whataman@home.com>
Re: How to use Shift and GetOpts <mgjv@tradingpost.com.au>
Re: How to use Shift and GetOpts (Garry Williams)
I'm Scared of Signal Processing <whataman@home.com>
Re: Issues when developing on windows systems and runni <jurgenex@hotmail.com>
Re: Issues when developing on windows systems and runni <mgjv@tradingpost.com.au>
logwatch.cgi / "tailing" log files on windows (Anthony)
Re: logwatch.cgi / "tailing" log files on windows <wuerz@yahoo.com>
need help with simple script <khirv@hotmail.com>
need help with simple script <khirv@hotmail.com>
Re: need help with simple script <mgjv@tradingpost.com.au>
Re: need help with simple script <mgjv@tradingpost.com.au>
Re: need help, error correction <jurgenex@hotmail.com>
Re: RegEx problem -- trying to match To: or From: at be (Chas Friedman)
Re: RegEx problem -- trying to match To: or From: at be <Tassilo.Parseval@post.rwth-aachen.de>
temporary file deleting too soon (Keith Clay)
Re: temporary file deleting too soon <nobody@nowhere.com>
Re: Unencoding <geoff@REMOVETHISgeoffball.net>
Re: Unencoding <geoff@REMOVETHISgeoffball.net>
Re: Unencoding <mgjv@tradingpost.com.au>
Re: Unencoding <geoff@REMOVETHISgeoffball.net>
web page editing with browser (Ifan Payne)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Nov 2001 11:55:07 +0900
From: "Dong-Gi Jo" <infowell@kisdi.re.kr>
Subject: [Q] Using index in Associate Arrary
Message-Id: <9sq1kj$os2$1@news1.kornet.net>
Please help me solve the following problem.
I am tring to extract values of the following form(e.g):
<form .....>
...
<input type=text name=N1>100
<input type=text name=N2>300
....
<input type=text name=N8>100
</form>
I have tried like this:
...
for $i (1 ... 8 ) {
push (@N, $in{'N$i'});
}
$N_List = join("\|", @N);
but $N_list returns blanks sperated by "|".
It looks like $in{'N$i'} doesn't work. I there any simple way to extract
many form values?
TIA
------------------------------
Date: Tue, 13 Nov 2001 03:16:44 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: [Q] Using index in Associate Arrary
Message-Id: <slrn9v145j.6ia.mgjv@verbruggen.comdyn.com.au>
Subject: Re: [Q] Using index in Associate Arrary
I suspect you meant to say "associative array"; nowadays these
things are simply called "hash" in Perl.
On Tue, 13 Nov 2001 11:55:07 +0900,
Dong-Gi Jo <infowell@kisdi.re.kr> wrote:
> Please help me solve the following problem.
>
> I am tring to extract values of the following form(e.g):
>
><form .....>
> ...
><input type=text name=N1>100
><input type=text name=N2>300
> ....
><input type=text name=N8>100
>
></form>
Then you should probably use the CGI module, which has many, many
useful functions to deal with forms and other CGI specific stuff.
> I have tried like this:
> ...
> for $i (1 ... 8 ) {
> push (@N, $in{'N$i'});
> }
Where did %in come from?
You are not using 'use strict;', are you? You should. You should also
enable warnings if you haven't done so already.
Apart from that, I think you meant
for my $i (1 .. 8) {
push @N, $in{"N$i"};
}
Note the double quotes, instead of the single ones (you're looking for
the literal key N$i 8 times). Also note the .. operator instead of
the ... one. Both will work, but it's much more common to use ..
unless you really need the semantics of ... in scalar context[1].
> $N_List = join("\|", @N);
No need to backwhack the vertical bar. It's not special in double
quoted strings.
> but $N_list returns blanks sperated by "|".
> It looks like $in{'N$i'} doesn't work. I there any simple way to extract
> many form values?
If you told us where %in was created and filled, then maybe we could
help. Right now, we can't.
Assuming you really want these things in an array (where they will
lose identity):
#!/usr/local/bin/perl -w
use strict;
use CGI qw(:standard);
my @N;
push @N, param("N$_") for 1..8;
my $N_List = join("|", @N);
But I don't think this is really what you want, just what you think
you want.
Martien
[1] The documentation is not really explicit about whether or not ...
_should_ behave like .. in list context. There is some phrase
under scalar context that claims that <<In all other regards,
"..." behaves just like ".." does.>>, but it's not that clear
whether this includes the earlier discussed list context.
--
|
Martien Verbruggen | Useful Statistic: 75% of the people
Trading Post Australia Pty Ltd | make up 3/4 of the population.
|
------------------------------
Date: Tue, 13 Nov 2001 03:55:26 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Can I make one perl cgi script work both in linux and in windows?
Message-Id: <slrn9v16dd.o13.efflandt@typhoon.xnet.com>
On Mon, 12 Nov 2001 15:24:18 -0500, Shi Jin <sj88@cornell.edu> wrote:
> in linux , the first line should be
> #!/usr/bin/perl
> But in windows, it should be
> #!E:\cygwin\bin\perl.exe
> How can I make it work in both systems?
> Thanks a lot.
On a similar note when using Perl scripts on different Unix systems that
have Perl in different paths (and not both), write a Perl script for eash
system that traverses that part of the directory tree, reads the first
line of every text file (or specific file extensions), and if it is a
shebang line that is not the proper path for that system, change it
automatically.
Or if that is too uncertain, write it so you can enter a list of filenames
you want to check on the commandline of the conversion script.
--
David Efflandt - All spam is 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: Tue, 13 Nov 2001 02:07:15 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: comp.lang.perl
Message-Id: <3BF0806C.689D5983@home.com>
Good to see you back. I've been concerned about you. I haven't seen a
post from you since the 9-11 WTC tragedy. Glad to know you are OK.
--Regards,
---Dennis
"Godzilla!" wrote:
>
> Stuart Gall wrote:
>
> (carefully clerically censored)
>
>
> > I have seen many people say this group has been rmgrouped 5 years ago. I
> > have seen the URLs stating that it is so.
>
> > Or since I have the group maybe I should go on a crucade posting a "this
> > group is dead please go to comp.lang.perl.misc " message every two weeks.
>
> There exists another newsgroup you should add to your Cleric "Crucade" to be
> sure all infidel groups are exterminated before they lead to a dire demise
> of all USENET. This dangerous nonbeliever group is alt.perl which does present,
> as all other rogue newsgroups do, a clear and present danger to the health and
> happiness of all internet denizens.
>
> Godzilla! Queen Of Perl Heritics.
------------------------------
Date: Mon, 12 Nov 2001 18:28:56 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: comp.lang.perl
Message-Id: <3BF08568.ED439029@stomp.stomp.tokyo>
What A Man ! wrote:
> Good to see you back.
My backside is not all that good to see; it is
an ample eyeful.
> I've been concerned about you.
This is dubious. Most likely you are becoming
bored with arguing with yourself.
> I haven't seen a post from you since the 9-11 WTC tragedy.
Perhaps amongst the worst of American tragedies. Certainly
an extremely sad and heart rendering event. Nonetheless,
we Americans have quite the knack for strong recovery and
regaining our stance with even greater strength.
I am filling in for an English teacher on maternity leave.
Glad it isn't me.
*checks her knot*
Very glad.
> Glad to know you are OK.
My shrink indicates otherwise.
Godzilla!
------------------------------
Date: Tue, 13 Nov 2001 02:15:53 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: How to use Shift and GetOpts
Message-Id: <3BF08272.4D822F11@home.com>
Garry Williams wrote:
>
> On Sun, 11 Nov 2001 12:58:38 -0600 (CST), BUCK NAKED1
> <dennis100@webtv.net> wrote:
>
> > After reviewing the docs on "Getopt" and "shift", I still don't
> > understand how to use them. What does the below "shift" and "opts"
> > codes do, and how would you enter a directory name while using
> > "shift"?
> >
> > use Getopt::Std;
> > use Net::FTP;
> > use Cwd;
> > getopts("dD");
>
> Now the @ARGV array has been shifted to remove all of the options that
> were on the command line leaving only the words after the last option
> or after the `--'.
>
> The return value of getopts() should be checked to see if it
> encountered any errors. It's often as easy as
>
> getopts("dD") or die $usage;
>
> > defined($opt_d) or $opt_d = 0;
> > defined($opt_D) or $opt_D = 0;
>
> Not sure why you do this. Either way the _boolian_ value will be
> false, if the option wasn't specified.
>
> > my $dir = shift;
>
> The variable $dir will now contain whatever word was left on the
> command line after getopts() consumed the options.
>
> > my $dir = "temp_dir";
>
> This declaration masks the first one, thus the first one is no longer
> accessible. You are enabling warnings, aren't you? That would have
> told you about the problem.
>
> --
> Garry Williams
I still don't understand how to use GetOpts, but thanks for the
information. I should have looked at the GetOpt::Long documentation. I
just discovered that it explains it better than the GetOpt::Std
documentation that I reviewed.
As far as "shift" goes, can you just tell me why people use something
like
my $dir = shift;
and how do you put a directory name in that if you're not in that
directory? ( I thought I read that "shift" without an argument uses @_
for its argument )
Thanks again
--Dennis
------------------------------
Date: Tue, 13 Nov 2001 02:28:12 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How to use Shift and GetOpts
Message-Id: <slrn9v11ak.2q5.mgjv@verbruggen.comdyn.com.au>
On Tue, 13 Nov 2001 02:15:53 GMT,
What A Man ! <whataman@home.com> wrote:
[snip of stuff about Getopt::Std not related to this question]
> As far as "shift" goes, can you just tell me why people use something
> like
> my $dir = shift;
> and how do you put a directory name in that if you're not in that
> directory? ( I thought I read that "shift" without an argument uses @_
> for its argument )
When you find yourself _thinking_ that a Perl operator or function
does something, you can read up on it in the perlop or perlfunc
documentation. This one, shift, is documented in perlfunc, so...
$ perldoc -f shift
shift ARRAY
shift Shifts the first value of the array off and
returns it, shortening the array by 1 and moving
everything down. If there are no elements in the
array, returns the undefined value. If ARRAY is
omitted, shifts the "@_" array within the lexical
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
scope of subroutines and formats, and the "@ARGV"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
array at file scopes or within the lexical scopes
^^^^^^^^^^^^^^^^^^^^
established by the "eval ''", "BEGIN {}", "INIT
{}", "CHECK {}", and "END {}" constructs.
[SNIP]
In the case you're talking about, it shifts the first argument from
@ARGV, which is documented in the perlvar documentation to contain the
command line arguments on program startup[1].
What exactly you mean by "how do you put a directory name in that" is
hard to say. If you pass a directory name as an argument, you can
shift that off.
#!/usr/local/bin/perl -w
use strict;
my $dir = shift;
__END__
This program will have the first argument given to it in the variable
$dir, after which the @ARGV array is one shorter.
Please, spend some time reading the various pieces of documentation,
and experimenting with some simple code.
Martien
[1] Note that this array can be modified, for example by the various
Getopt:: modules.
--
|
Martien Verbruggen | I used to have a Heisenbergmobile.
Trading Post Australia Pty Ltd | Every time I looked at the
| speedometer, I got lost.
------------------------------
Date: Tue, 13 Nov 2001 03:23:52 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: How to use Shift and GetOpts
Message-Id: <slrn9v14i9.2us.garry@zfw.zvolve.net>
On Tue, 13 Nov 2001 02:15:53 GMT, What A Man ! <whataman@home.com>
wrote:
> Garry Williams wrote:
>> On Sun, 11 Nov 2001 12:58:38 -0600 (CST), BUCK NAKED1
>> <dennis100@webtv.net> wrote:
>>
>> > After reviewing the docs on "Getopt" and "shift", I still don't
>> > understand how to use them. What does the below "shift" and "opts"
>> > codes do, and how would you enter a directory name while using
>> > "shift"?
>> >
>> > use Getopt::Std;
>> > use Net::FTP;
>> > use Cwd;
>> > getopts("dD");
[snip]
>> > my $dir = shift;
>>
>> The variable $dir will now contain whatever word was left on the
>> command line after getopts() consumed the options.
[snip]
> I still don't understand how to use GetOpts, but thanks for the
> information. I should have looked at the GetOpt::Long documentation. I
> just discovered that it explains it better than the GetOpt::Std
> documentation that I reviewed.
Well, the manual page for Getopt::Std is a bit brief, but here's the
story:
command -D -d some-other-word
If the above command is used and the `command' script uses
getopts("dD");
then the `command' script will find one element in @ARGV,
"some-other-word" and $main::opt_d and $main::opt_D will both be set
to the value 1.
getopts() will modify the @ARGV array to remove anything that it
processes from the front of that array.
Passing an option letter *without* a colon `:' to getopts() means that
the option does *not* take a value, co the word "some-other-word"
after `-D' will not be "consumed" from @ARGV, but the two words `-d'
and `-D' *will* be consumed or shifted off of @ARGV.
> As far as "shift" goes, can you just tell me why people use something
> like
> my $dir = shift;
To place the first element of the @ARGV array in the variable $dir.
> and how do you put a directory name in that if you're not in that
> directory?
Huh? I don't understand that.
> ( I thought I read that "shift" without an argument uses @_
> for its argument )
Don't guess about it, read about it in the perlfunc manual page, shift
section. You can do that with
perldoc -f shift
That tells you that @ARGV is shift()ed, if the shift operator is
within the file scope (not within the lexical scope of a subroutine).
--
Garry Williams
------------------------------
Date: Tue, 13 Nov 2001 02:41:46 GMT
From: "What A Man !" <whataman@home.com>
Subject: I'm Scared of Signal Processing
Message-Id: <3BF08883.904D13EA@home.com>
Is signal processing dangerous to us amateur perlers? I've studied
perlsec. The reason I'm asking is because Ben Goldberg graciously posted
the code below recently; but when I modified the coding below (I think I
removed a couple of lines), it left a process running (over process
limit) that caused my server to shut me down for a few days, so I went
back to just using a plain "open" or "system" to execute the program.
While I'm on the subject, how do I check to see if any processes were
left running on a webserver? and how do I turn them off?
use IPC::Open2;
open( TMPFILE, "<$tmpfile" )
or die "Couldn't open $tmpfile for reading: $!";
my $g_pid = open2(FROM_GUNZIP, "<&TMPFILE", "gunzip", "-c", "-d");
my $t_pid = open2(FROM_TAR, "<&FROM_GUNZIP", "tar", "tf", "-");
if( my @tar_output = <FROM_TAR> ) {
print "Success! The tar file contains the following:\n";
print @tar_output;
} else {
print "Failure!\n";
print "Either the tar file empty, or something screwed up.\n";
}
if( waitpid $g_pid, 0 ) {
my ($sig, $ret) = ($? & 255, $? >> 8);
die "gunzip died from signal $sig" if $sig;
die "gunzip exited with code $ret" if $ret;
} else {
die "Somebody musta reaped my gunzip process: $!";
}
if( waitpid $t_pid, 0 ) {
my ($sig, $ret) = ($? & 255, $? >> 8);
die "tar died from signal $sig" if $sig;
die "tar exited with code $ret" if $ret;
} else {
die "Somebody musta reaped my tar process: $!";
}
END: {
kill SIGKILL => $g_pid, $t_pid;
}
__END__
Thanks for your reply,
Dennis
------------------------------
Date: Mon, 12 Nov 2001 18:08:52 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Issues when developing on windows systems and running on linux boxes????
Message-Id: <3bf08173@news.microsoft.com>
"Bob Rock" <no_spam.yet_another_apprentice@hotmail.com> wrote in message
news:9shkm6$1412q2$1@ID-98646.news.dfncis.de...
> >
> > Yes, that situation can cause problems, if people are careless.
> >
>
> And what can be done? Is there a text editor for win32 systems
What about e.g. emacs?
> to convert
> "win32" newlines (carriage return + newline characters) in "linux"
newlines
> (only a newline character)? Thank you.
dos2unix
Or you could set the proper parameters in the FTP program when transfering
the files from Windows to Unix. Or, or, or ....
There are many ways to change the line end markers.
But actually the line end marker is only a very minor problem.
You need to write *portable* code!
This means e.g.
- don't use the backslash in directory pathes
- don't use system specific features (Win32::API would be an obvious
example)
- don't call external program unless you are sure they exist on the Unix
box, too.
- etc., etc.
Oddly enough I couldn't find an entry in the FAQ about this topic (but maybe
I jsut searched for the wrong key words).
jue
------------------------------
Date: Tue, 13 Nov 2001 02:19:55 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Issues when developing on windows systems and running on linux boxes????
Message-Id: <slrn9v10r2.2q5.mgjv@verbruggen.comdyn.com.au>
On Mon, 12 Nov 2001 18:08:52 -0800,
Jürgen Exner <jurgenex@hotmail.com> wrote:
[discussion on creating perl source files on win32, and running them
on linux, attribution was already broken]
> You need to write *portable* code!
[snip]
> Oddly enough I couldn't find an entry in the FAQ about this topic (but maybe
> I jsut searched for the wrong key words).
Have a look at the perlport documentation. It goes into quite some
detail on writing portable Perl.
Martien
--
|
Martien Verbruggen | This matter is best disposed of from
Trading Post Australia Pty Ltd | a great height, over water.
|
------------------------------
Date: 12 Nov 2001 21:28:08 -0800
From: fallingdownagain@crosswinds.net (Anthony)
Subject: logwatch.cgi / "tailing" log files on windows
Message-Id: <97827c63.0111122128.126e48b4@posting.google.com>
Hello,
I'm running Apache v1.3.22 on Windows 2000. I installed ActiveState
ActivePerl v5.6, and I'm trying to use this logwatch.cgi script:
http://www.cgi.tj/scripts/logwatch.html
The problem is that it needs a "tail" something-or-other... I don't
know if that's a program (an *.exe on Windows) or a function (a dll?)
or a script itself (*.cgi or *.pl maybe??).
In my searchings I've learned that this functionality is built into
Unix, but needs to be somehow added to Windows. I've searched the net
and found 9 different tail.exe programs, none of which work. I copy
them to my perl\bin directory, and try each one, but they either do
nothing, or hang.
Should I be looking for a tail.pl or tail.cgi instead of an
executeable? Or am I totally off the mark here?
Any help at all would be greatly appreciated.
Anthony
http://NoDivisions.com
------------------------------
Date: 13 Nov 2001 00:35:19 -0500
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: logwatch.cgi / "tailing" log files on windows
Message-Id: <m3668fi67c.fsf@DCCMBX01.njitdm.campus.njit.edu>
fallingdownagain@crosswinds.net (Anthony) writes:
> The problem is that it needs a "tail" something-or-other... I don't
> Should I be looking for a tail.pl or tail.cgi instead of an
> executeable? Or am I totally off the mark here?
Maybe
perldoc -q tail
would get you started.
--
$_="\n,rekcah egnufeB rehtona tsuJ";#v1<?>g\:pv-<5<
s s\S+(?:B)sunpack'u',q q$;')E4qsee;#>60#^<(v!<)g6<
print scalar reverse,$@ unless m,[+;#]55,;m:_,:#^1<
------------------------------
Date: Tue, 13 Nov 2001 11:09:49 +0800
From: "blongk" <khirv@hotmail.com>
Subject: need help with simple script
Message-Id: <3bf08f76$1_2@news.tm.net.my>
I have a perl script that lists the hash keys and the values like this:
#!/usr/local/bin/perl -w
#This file extracts user ids and their respective genders from hypsex file
that contains user ids and genders.
my $B = "uidnsex";
my $C = "allsex";
my %allsex;
open (B, "< $B") || die ("can not open $B because $!\n");
#my $id;
#my $sex;
while (my $id = <B>) {
my $sex = <B>;
chomp($id);
chomp($sex);
$allsex{$id} = $sex;
}
close (B);
open (C, "> $C") || die ("can not open $C because $!\n");
foreach $id (keys %allsex) {
print C "$id $allsex{$id} \n";
}
close (C);
the file uidnsex entries are like these:
id1
M
id2
M
id3
F
id4
M
id5
F
id6
F
and so on....
the output file, allsex will be like this:
id1 M
id3 F
id4 M
id6 F
id2 M
id5 F
and so on....
As long as the entries in the uidnsex do not exceed 54 lines, the output is
always as expected but once it exceeds that, let say 56 entries in uidnsex
file, one of the entries in the output file will be missing. The more
entries I have in uidnsex file, the more entries in the output file are
missing. Why does this happen? Can anyone please help. Thank you.
------------------------------
Date: Tue, 13 Nov 2001 11:58:42 +0800
From: "blongk" <khirv@hotmail.com>
Subject: need help with simple script
Message-Id: <3bf09aeb$1_2@news.tm.net.my>
I have a perl script that lists the hash keys and the values like this:
#!/usr/local/bin/perl -w
#This file extracts user ids and their respective genders from hypsex file
that contains user ids and genders.
my $B = "uidnsex";
my $C = "allsex";
my %allsex;
open (B, "< $B") || die ("can not open $B because $!\n");
#my $id;
#my $sex;
while (my $id = <B>) {
my $sex = <B>;
chomp($id);
chomp($sex);
$allsex{$id} = $sex;
}
close (B);
open (C, "> $C") || die ("can not open $C because $!\n");
foreach $id (keys %allsex) {
print C "$id $allsex{$id} \n";
}
close (C);
the file uidnsex entries are like these:
id1
M
id2
M
id3
F
id4
M
id5
F
id6
F
and so on....
the output file, allsex will be like this:
id1 M
id3 F
id4 M
id6 F
id2 M
id5 F
and so on....
As long as the entries in the uidnsex do not exceed 54 lines, the output is
always as expected but Once it exceeds that, let say 56 entries in uidnsex
file, one of the entries in the output file will be missing. The more
entries I have in uidnsex file, the more entries in the output file are
missing. Why does this happen? Can anyone please help. Thank you.
------------------------------
Date: Tue, 13 Nov 2001 04:09:34 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: need help with simple script
Message-Id: <slrn9v178l.6ia.mgjv@verbruggen.comdyn.com.au>
On Tue, 13 Nov 2001 11:09:49 +0800,
blongk <khirv@hotmail.com> wrote:
> I have a perl script that lists the hash keys and the values like this:
>
> #!/usr/local/bin/perl -w
> #This file extracts user ids and their respective genders from hypsex file
> that contains user ids and genders.
You do already lexically scope all your variables. You should
therefore use the strict pragma to enforce scoped and qualified names.
It'll help you while debugging.
> my $B = "uidnsex";
> my $C = "allsex";
Choose better variable names.
my $infile = "uidnsex";
my $outfile = "allsex";
> my %allsex;
>
> open (B, "< $B") || die ("can not open $B because $!\n");
> #my $id;
> #my $sex;
> while (my $id = <B>) {
> my $sex = <B>;
You might want to add some checks to see whether both variables have
been successfully set, unless you can guarantee that your input will
never be corrupt.
> chomp($id);
> chomp($sex);
> $allsex{$id} = $sex;
> }
> close (B);
>
> open (C, "> $C") || die ("can not open $C because $!\n");
>
> foreach $id (keys %allsex) {
foreach my $id (keys %allsex) {
> print C "$id $allsex{$id} \n";
> }
>
> close (C);
>
> the file uidnsex entries are like these:
> id1
> M
> id2
> M
> id3
> F
> id4
> M
> id5
> F
> id6
> F
> and so on....
>
> the output file, allsex will be like this:
>
> id1 M
> id3 F
> id4 M
> id6 F
> id2 M
> id5 F
> and so on....
>
> As long as the entries in the uidnsex do not exceed 54 lines, the output is
> always as expected but once it exceeds that, let say 56 entries in uidnsex
> file, one of the entries in the output file will be missing. The more
> entries I have in uidnsex file, the more entries in the output file are
> missing. Why does this happen? Can anyone please help. Thank you.
I can only come up with one explanation: Your ids are NOT unique.
Could you investigate that? If your ids are supposed to be unique,
then I would rewrite your program as:
#!/usr/local/bin/perl -w
use strict;
while(my $id = <>)
{
my $sex = <> || die "No sex on line $.\n"; # :)
chomp($id, $sex);
print "$id\t$sex\n";
}
__END__
And call it like this:
$ some_program < uidnsex > allsex
If the uids are not supposed to be unique, I would first of all change
the name, and not call it "id" anymore, and secondly, I'd specify what
needs to happen when there's more than one.
Martien
--
|
Martien Verbruggen | For heaven's sake, don't TRY to be
Trading Post Australia Pty Ltd | cynical. It's perfectly easy to be
| cynical.
------------------------------
Date: Tue, 13 Nov 2001 04:24:33 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: need help with simple script
Message-Id: <slrn9v184p.6ia.mgjv@verbruggen.comdyn.com.au>
On Tue, 13 Nov 2001 11:58:42 +0800,
blongk <khirv@hotmail.com> wrote:
> I have a perl script that lists the hash keys and the values like this:
You just posted this question, and I have just answered it. Please try
to not post the same question more than once. Even if it doesn't show
up right away in your news reader, wait a little while before
concluding that the post went wrong. Usenet isn't instantaneous.
Thanks,
Martien
--
|
Martien Verbruggen | That's not a lie, it's a
Trading Post Australia Pty Ltd | terminological inexactitude.
|
------------------------------
Date: Mon, 12 Nov 2001 18:42:35 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: need help, error correction
Message-Id: <3bf088ee@news.microsoft.com>
"MAGiC MANiAC^mTo" <no_mto@hotmail.com> wrote in message
news:9sf2gt$172c$1@news.kabelfoon.nl...
[...]
> I do know its full with errors, but I'm just a beginner and would like to
> learn this language...
[...]
> P.s. I don't want to use CGI.pm, or such kind of...
Well, this combination is almost like asking for desaster.
There may be valid reasons not to use CGI.pm (or one of the other standard
modules for CGI handling). But trying to re-implement core CGI functionality
while trying to learn Perl at the same time is making both jobs at least
four times harder.
If you want to learn Perl then I suggest you stick with CGI.pm. That module
is certainly better suited than any home-brewed code you could come up with.
And if you want to learn about the pitfall of the CGI protocol then maybe
you should stay with a language you already know.
jue
------------------------------
Date: Tue, 13 Nov 2001 03:30:34 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <3bf0932a.16597728@news.itouch.net>
On Tue, 13 Nov 2001 01:29:52 GMT, "Steve Grazzini"
<s_grazzini@hotmail.com> wrote:
>
>"Chas Friedman" <friedman@math.utexas.edu> wrote in message
>news:3bf02ccd.58387537@news.itouch.net...
>> On Mon, 12 Nov 2001 12:00:08 -0800, "jennyw"
>> <donotspam-jen@dangerousideas.com> wrote:
>[..]
>> Incidentally, you may have to worry about the fact that an email
>> might contain other lines beginning with "From" or "To". Emails
>> usually begin with a header "From ...". The sender usually is on a
>> line beginning with "From: " There may also be lines in the body of
>> the email beginning with "From " or "To ".
>[..]
>
>You'll always get a blank line between the header and the body of the
>message, though. So you can bail before the body of the message, the jpeg
>attachment, the .xls, etc.
>
>while(<MAIL>) {
> last if /^$/;
> # do your thing with the headers
>}
That's true. However, if you have a file with many emails, it can be
tricky to figure out exactly which lines containing "From " at the
beginning are header lines. Most mail programs replace "From " with
">From " or some such thing if it occurs at the beginning of a
non-header line for just this reason.
cf
------------------------------
Date: Tue, 13 Nov 2001 08:02:53 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9sqgit$8a8$01$1@news.t-online.com>
On Tue, 13 Nov 2001 03:30:34 GMT, Chas Friedman wrote:
>>while(<MAIL>) {
>> last if /^$/;
>> # do your thing with the headers
>>}
> That's true. However, if you have a file with many emails, it can be
> tricky to figure out exactly which lines containing "From " at the
> beginning are header lines. Most mail programs replace "From " with
> ">From " or some such thing if it occurs at the beginning of a
> non-header line for just this reason.
As a matter of fact a /^From/ is always the first line of a message, so
any other From's in the body are mandatory to be escaped according
to the relevant RFCs (822 and 2822). Hence I wouldn't worry so much about
parsing an mbox. A valid one does not have any ambiguities.
Tassilo
--
All the evidence concerning the universe has not yet been collected,
so there's still hope.
------------------------------
Date: 12 Nov 2001 23:24:17 -0800
From: clayk@acu.edu (Keith Clay)
Subject: temporary file deleting too soon
Message-Id: <8947fc5.0111122324.1420253@posting.google.com>
Folks,
I am using modperl to read a picture out of a database, create a temp
file, using an <img> to display the image and then deleting the file
using an Apache->request->register_cleanup(\&cleanup).
Here is the code that gets the photo file name from a module I have
written (the module has the cleanup registered.)
my $photo=$in->photo;
unless ( $photo ) {
print "<h3>No Photo available for this person.";
}
else {
print "<img align=left src=\"$photo\" alt=\"Photo of
$uid\">";
}
After this, I build two tables of different user information with data
from a mysql database. The problem is that I get the 'alt'
description and the file gets removed before it can be displayed.
I can put a 5 second delay in the cleanup sub and it works fine. I do
have $|=1 in both the module and the script.
This is mod_perl 1.22/Apache 1.3.9 and perl 5005003. We can't update
these because our production system is using these versions.
THanks,
keith
------------------------------
Date: Tue, 13 Nov 2001 17:52:27 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: temporary file deleting too soon
Message-Id: <hg4I7.231908$8x1.39980@newsfeeds.bigpond.com>
"Keith Clay" <clayk@acu.edu> wrote in message
news:8947fc5.0111122324.1420253@posting.google.com...
> Folks,
>
> I am using modperl to read a picture out of a database, create a temp
> file, using an <img> to display the image and then deleting the file
> using an Apache->request->register_cleanup(\&cleanup).
>
> Here is the code that gets the photo file name from a module I have
> written (the module has the cleanup registered.)
>
> my $photo=$in->photo;
> unless ( $photo ) {
> print "<h3>No Photo available for this person.";
> }
> else {
> print "<img align=left src=\"$photo\" alt=\"Photo of
> $uid\">";
> }
>
> After this, I build two tables of different user information with data
> from a mysql database. The problem is that I get the 'alt'
> description and the file gets removed before it can be displayed.
>
> I can put a 5 second delay in the cleanup sub and it works fine. I do
> have $|=1 in both the module and the script.
I had a similar problem generating stock charts on the fly using GD. The
bottom line is the client(browser) and server (apache) processes operate
asynchronously. You cannot rely on any particular line speed.
You may want to write the image file and run a periodic cron job that
deletes old files. An alternative that I have not explored yet is using an
apache rewrite rule to run a program whenever an .gif or .jpg image is
requested.
gtoomey
------------------------------
Date: Tue, 13 Nov 2001 05:33:16 GMT
From: "Geoff" <geoff@REMOVETHISgeoffball.net>
Subject: Re: Unencoding
Message-Id: <wg2I7.49236$i4.7803173@news0.telusplanet.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9v0jgl.2q5.mgjv@verbruggen.comdyn.com.au...
> > $code =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> Assuming that the OP does indeed need this to decode URLs or query
> strings:
>
> iWouldn't the code you give only work on machines where the
> character collation is the same as specified for these escape codes?
> This will be largely true on machines with ASCII based character sets,
> but I doubt it will work correctly on EBCDIC machines, for example.
>
> Has anyone tried this approach on EBCDIC machines? Or the reverse with
>
> sprintf "%%%02x", ord $char
>
> Martien
What's an example of a system that would use this? Windows, Unix, and
Solaris all use ASCII (not sure about Macs, but I think they do too).
Geoff
------------------------------
Date: Tue, 13 Nov 2001 06:01:41 GMT
From: "Geoff" <geoff@REMOVETHISgeoffball.net>
Subject: Re: Unencoding
Message-Id: <9H2I7.49272$i4.7818612@news0.telusplanet.net>
"Skeleton Man" <invalid_email@www.skeleton-man.f2s.com> wrote in message
news:3bf05a75$1_1@news.iprimus.com.au...
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
>
> This is whar I use to get and process form data, and that particular line
> works fine for me..
> --
> Regards,
> Chris
> (Webmaster, http://www.skeleton-man.f2s.com)
Thanks Chris. That's almost identical to mine, with the exceptions being
I've used s/// instead of tr/// for converting a + to a space, and just used
$pairs[1] (whenever I only need the value, and not the name of each
textbox).
Geoff
------------------------------
Date: Tue, 13 Nov 2001 18:15:57 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Unencoding
Message-Id: <slrn9v1i5d.f5j.mgjv@martien.heliotrope.home>
On Tue, 13 Nov 2001 05:33:16 GMT,
Geoff <geoff@REMOVETHISgeoffball.net> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn9v0jgl.2q5.mgjv@verbruggen.comdyn.com.au...
>
>> > $code =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
>> Has anyone tried this approach on EBCDIC machines? Or the reverse with
>>
>> sprintf "%%%02x", ord $char
>>
>> Martien
>
> What's an example of a system that would use this? Windows, Unix, and
> Solaris all use ASCII (not sure about Macs, but I think they do too).
$ man perlport
[snip]
EBCDIC Platforms
Recent versions of Perl have been ported to platforms such
as OS/400 on AS/400 minicomputers as well as OS/390,
VM/ESA, and BS2000 for S/390 Mainframes. Such computers
use EBCDIC character sets internally (usually Character
Code Set ID 0037 for OS/400 and either 1047 or POSIX-BC
for S/390 systems). On the mainframe perl currently works
under the "Unix system services for OS/390" (formerly
known as OpenEdition), VM/ESA OpenEdition, or the BS200
POSIX-BC system (BS2000 is supported in perl 5.6 and
greater). See the perlos390 manpage for details.
[snip]
Martien
--
|
Martien Verbruggen | We are born naked, wet and hungry.
| Then things get worse.
|
------------------------------
Date: Tue, 13 Nov 2001 07:57:27 GMT
From: "Geoff" <geoff@REMOVETHISgeoffball.net>
Subject: Re: Unencoding
Message-Id: <Hn4I7.49340$i4.7878391@news0.telusplanet.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9v1i5d.f5j.mgjv@martien.heliotrope.home...
> On Tue, 13 Nov 2001 05:33:16 GMT,
> Geoff <geoff@REMOVETHISgeoffball.net> wrote:
> > "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> > news:slrn9v0jgl.2q5.mgjv@verbruggen.comdyn.com.au...
> >
> >> > $code =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> >
> >> Has anyone tried this approach on EBCDIC machines? Or the reverse with
> >>
> >> sprintf "%%%02x", ord $char
> >>
> >> Martien
> >
> > What's an example of a system that would use this? Windows, Unix, and
> > Solaris all use ASCII (not sure about Macs, but I think they do too).
>
> $ man perlport
> [snip]
> EBCDIC Platforms
>
> Recent versions of Perl have been ported to platforms such
> as OS/400 on AS/400 minicomputers as well as OS/390,
> VM/ESA, and BS2000 for S/390 Mainframes. Such computers
> use EBCDIC character sets internally (usually Character
> Code Set ID 0037 for OS/400 and either 1047 or POSIX-BC
> for S/390 systems). On the mainframe perl currently works
> under the "Unix system services for OS/390" (formerly
> known as OpenEdition), VM/ESA OpenEdition, or the BS200
> POSIX-BC system (BS2000 is supported in perl 5.6 and
> greater). See the perlos390 manpage for details.
> [snip]
>
> Martien
Duly noted, but how many people are going to be:
1) Using these computers? (they look like servers)
2) Using these computers to browse the internet?
3) Actually visit the site which is using theis Perl script?
Geoff
------------------------------
Date: 12 Nov 2001 20:34:53 -0800
From: ip@dot-solutions.net (Ifan Payne)
Subject: web page editing with browser
Message-Id: <49a7136c.0111122034.1e4cdb95@posting.google.com>
Could anyone suggest a free PERL script that enables editing of web
pages via a browser? I am looking for a way for users to edit/add
information to their web pages with thier browsers.
------------------------------
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 2120
***************************************