[22663] in Perl-Users-Digest
Perl-Users Digest, Issue: 4884 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 24 06:06:03 2003
Date: Thu, 24 Apr 2003 03: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)
Perl-Users Digest Thu, 24 Apr 2003 Volume: 10 Number: 4884
Today's topics:
Re: Advice: Perl + XML - Native Perl module? (Randal L. Schwartz)
Creating udp sockets using IO::Socket <imarine@bigpond.net.au>
Re: Creating udp sockets using IO::Socket <uri@stemsystems.com>
Re: Distribute a perl script (Malcolm Dew-Jones)
Re: Distribute a perl script <simon.andrews@bbsrc.ac.uk>
Re: ftp script <simon.andrews@bbsrc.ac.uk>
Re: Little help (Anno Siegel)
Re: Little help <g4rry_short@zw4llet.com>
Re: looking for graphing program <wksmith@optonline.net>
Re: LWP::Simple "get" gets me one giant line. Want arr (David Efflandt)
Re: OT slightly: mod_perl vs JSP <ubl@schaffhausen.de>
Re: Parent & Child question: <markvalls.spambox@dnainternet.net>
Re: Parent & Child question: (Anno Siegel)
Re: Parent & Child question: <tassilo.parseval@rwth-aachen.de>
Re: Parent & Child question: (Anno Siegel)
Re: Parent & Child question: <tassilo.parseval@rwth-aachen.de>
Re: parsing perl code (audit, summarize, trace) <simon.andrews@bbsrc.ac.uk>
Re: Read File, write filename? (Joe Smith)
Re: regular expression question <wksmith@optonline.net>
Re: Still Stumped (Jay Tilton)
Re: Tough question for the guru's; Grep Once, Awk Twice <uri@stemsystems.com>
Re: Tough question for the guru's; Grep Once, Awk Twice (Jay Tilton)
Re: Tough question for the guru's; Grep Once, Awk Twice (Jay Tilton)
Re: Tough question for the guru's; Grep Once, Awk Twice (Tad McClellan)
Re: Tough question for the guru's; Grep Once, Awk Twice (Tad McClellan)
Re: Tough question for the guru's; Grep Once, Awk Twice (Tad McClellan)
Re: Tough question for the guru's; Grep Once, Awk Twice (Tad McClellan)
Re: Tough question for the guru's; Grep Once, Awk Twice <mgjv@tradingpost.com.au>
Re: Tough question for the guru's; Grep Once, Awk Twice <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Apr 2003 05:53:17 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Advice: Perl + XML - Native Perl module?
Message-Id: <cec9ef5f127f8c370c19e13e484c4ad2@TeraNews>
>>>>> "MegaZone" == MegaZone <usenet@megazone.org> writes:
MegaZone> I was looking at lib::XML, but that's an XS wrapper to C -
MegaZone> performance isn't an overriding concern, but portability is.
MegaZone> If possible, I'd like to use an XML module that is native
MegaZone> Perl. (It looks like XML::Twig is, right?) Ideally the
MegaZone> code will end up portable across UNIX/Linux and Windows
MegaZone> platforms.
Interesting... "Pure Perl" "XML Parser"'s second hit in Google
(right now) is XML::SAX::PurePerl. Perhaps you can see if that
fits your needs. It does claim that it is <b>slow</b>. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 24 Apr 2003 07:05:50 GMT
From: Justin <imarine@bigpond.net.au>
Subject: Creating udp sockets using IO::Socket
Message-Id: <p33fav04t7e75o59o4c7o26t96g1jtvovu@4ax.com>
Hi all,
I've managed to create a TCP socket using IO::Socket::INET and am trying to do the same
method to create a UDP socket.
However it always fails. Can anyone give me some suggestions to to what the error might
be?
Cheers
Justin
------------------------------
Date: Thu, 24 Apr 2003 07:45:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Creating udp sockets using IO::Socket
Message-Id: <x7brywnxsx.fsf@mail.sysarch.com>
>>>>> "J" == Justin <imarine@bigpond.net.au> writes:
J> I've managed to create a TCP socket using IO::Socket::INET and am
J> trying to do the same method to create a UDP socket.
J> However it always fails. Can anyone give me some suggestions to to
J> what the error might be?
show some code. it helps us debug things.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 23 Apr 2003 21:55:31 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Distribute a perl script
Message-Id: <3ea76e43@news.victoria.tc.ca>
Patrice (google@ppatrice.ovh.org) wrote:
: I have done a perl script as a project for univeristy. I am now
: looking for a way to distribute it to my examiners so they can easily
: test it.
Did they not tell you the delivery format they wanted? My experience used
to be that the instructors knew exactly what they wanted, and it was the
students task to make everything fit the required delivery format.
------------------------------
Date: Thu, 24 Apr 2003 09:34:55 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Distribute a perl script
Message-Id: <3EA7A1AF.9090207@bbsrc.ac.uk>
Patrice wrote:
> I have done a perl script as a project for univeristy. I am now
> looking for a way to distribute it to my examiners so they can easily
> test it. By easly I mean without having anything to install. There's a
> high probability they have a windows machine, but I'd like to provide
> something for Linux as well.
> My script is using two modules : XML::LibXML and XML::LibXSLT
>
> I tried perlcc and pp to build linux executables. I succeed but a
> friend of mine tried both on his machine, and they didn't run because
> of an incompatible glibc. Anyway, for Linux I can assume there is a
> perl interpreter installed and just provide the source. But what about
> the modules ? Will it work if I also put the *.pm files along with my
> script ?
It should be safe to assume that the current directory will be in @INC
on a standard Linux setup, so you could just provide a tar file which
extracts your modules under the current directory. If you wanted to be
absolutely sure then just add:
use lib '.';
to your script.
Alternatively you could use the PAR module to bundle all your code up
into a singe file and pass that on. It will require a perl interpreter
to be installed, but nothing else. When you tried pp what you're
actually getting is a PAR archive with a bundled interpreter. The PAR
archives should also be platform independant, but the examiners would
need to have perl installed on their windows machine.
Hope this helps
Simon.
------------------------------
Date: Thu, 24 Apr 2003 08:48:31 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: ftp script
Message-Id: <3EA796CF.70603@bbsrc.ac.uk>
>>>>"Danny" <rrunner@san.rr.com> said:
>>>
>>>I do not know how to write scripts so I am asking for
>>>some help. I need to creat a script that will help me
>>>ftp a firmware to over 200 locations. I want it to do it
>>>using linux. Is there a way to do this and can anyone
>>>help me with some direction?
> "Tony Curtis" <tony_curtis32@yahoo.com> wrote
>
>>Net::FTP
Danny wrote:
> Net::Ftp is what I can use for this purpose.
Nope. Net::FTP is what you can use for this purpose. Case is important!
> I am really not a perl user but I have looked on cpan.org and
> found net::ftp.
> So do I create a file with a *.pl extension
Under Linux the name of your file is irrelevant. You need to make sure
that the first line of the file is:
#!/usr/bin/perl -w
and that it it has both read and execute permissions on it
chmod 755 yourfile
> with the commands for net::ftp for each site I need to do the
> ftp to?
The Net::FTP documentation shows a summary of how to use the module
(type perldoc Net::FTP after you have installed the module). You should
be able to adapt this to get something working. In your case the only
other command you'd need in addition to those in the short summary would be
$ftp -> put('some_file_name.txt');
to upload a file to a remote server.
After you have a simple script working which tranfers a single file to a
single server then you can think about adding the extra code you'd need
to run this in a loop stepping through each of the servers you want to
transfer the file to. I'd highly recommend getting a perl book if
you've never done any programming before (see http://learn.perl.org/)
for useful information.
If you get stuck then come back to the group with the code you have. It
would also be a good idea to read the posting guidelines posted here
regularly before doing this to ensure that you stand the best chance of
getting a useful answer.
> I would use this command to run the file $perl test-ftp.pl*
If the first line of your script points to the perl interpreter on your
system, and your file has read and execute permissions then you would
run it by typing
./test-ftp.pl
the same as any other program.
Hope this helps
Simon.
------------------------------
Date: 24 Apr 2003 08:11:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Little help
Message-Id: <b8866k$4j2$1@mamenchi.zrz.TU-Berlin.DE>
Erik Dokic <erik.dokic@volja.net> wrote in comp.lang.perl.misc:
> I need a little help with a Perl script. On Linux SuSE 8.1 I'd like to
> run a script which contains a line:
>
> open(XS,"/usr/X11R6/bin/xscreensaver-command -watch|") or die;
>
> The script is supposed to excecute commands when the screen saver
> starts/ends. But the file "xscreensaver" or something similar doesn't
> exist there or elsewhere. How should I modify this to make the script
> run?
What has this to do with Perl? Find xscreensaver and install it.
Anno
------------------------------
Date: Thu, 24 Apr 2003 09:39:13 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: Little help
Message-Id: <b887un$8jv$1$8300dec7@news.demon.co.uk>
Erik Dokic wrote:
> I need a little help with a Perl script. On Linux SuSE 8.1 I'd like to
> run a script which contains a line:
>
> open(XS,"/usr/X11R6/bin/xscreensaver-command -watch|") or die;
>
> The script is supposed to excecute commands when the screen saver
> starts/ends. But the file "xscreensaver" or something similar doesn't
> exist there or elsewhere. How should I modify this to make the script
> run?
>
> Thanks in advance!
How do you know xscreensaver-command doesn't exist? Have you tried
"whereis xscreensaver-command"
at the command prompt to check it's there?
How about supplying the rest of the script?
If the command really doesn't exist, you could try something like :
...
my $whatever = 1;
while ($whatever) {
sleep 300; # Sleep for 5 mins.
my $results = system("ps ux | grep xscreensaver | grep -v grep");
if ($results) {
# xscreensaver is currently running, so do whatever.
}
}
Not as tidy, maybe, but at least it works.
Regards,
Garry
------------------------------
Date: Thu, 24 Apr 2003 04:28:48 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: looking for graphing program
Message-Id: <4KJpa.108412$MB4.37504383@news4.srv.hcvlny.cv.net>
"Chris" <chris_12003@yahoo.com> wrote in message
news:vaekga867vgj9d@corp.supernews.com...
> Does anyone know of any graphing scripts that I can use that'll take
the
> input from a text file and display a graph to the user. The graph can
> either update automatically or through a crontab once a day. I'm
trying to
> create a bar chart with 2 values to plot and maybe 3 if thats
possible.
>
Did you check out the graphics section of CPAN?
Bill
------------------------------
Date: Thu, 24 Apr 2003 04:18:17 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: LWP::Simple "get" gets me one giant line. Want array!
Message-Id: <slrnbaepc9.qoq.efflandt@typhoon.xnet.com>
On Wed, 23 Apr 2003 23:14:41 GMT, John <SeeMessageBody@nospam.com> wrote:
> # The hard part's done! (i.e., reading a web page), but this always prints
> out "That page has 1 lines."
> # I want the lines of a web page in an array so I can search for certain
> strings.
> # Any ideas?
>
> use LWP::Simple;
> @content = get("http://www.cpan.org/");
>
> chomp @content; # Didn't help.
> print "That page has ", scalar @content, " lines.\n";
> print "@content";
Carriage returns or newlines in html are just whitespace, do not
necessarily represent html lines, and are not even required at all (an
html page can be all one text line). HTML linebreaks might be represented
by </p>, <p>, <br>, etc., or may wrap automatically based on your browser
window size. So you need to define what you consider a line and why it
even matters.
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 24 Apr 2003 09:12:46 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: OT slightly: mod_perl vs JSP
Message-Id: <b885un$rnb$1@news.dtag.de>
Richard Gration wrote:
> Hi
>
> Apache::Registry nearly does it for me, but the implicit handler function
> interferes with the scope of the request context vars which I declare and
> instantiate at the top of each cgi. I could as easily rewrite into
> mod_perl as Apache::Registry. (Well, nearly!)
>
> Apparently Resin beats mod_perl these days, at least according to the
> Resin website ;-) However, I agree with you about programming style. All
> I can say, is I'm usually trying to improve it :-)
I'd like to add one thing. You are in a way comparing apples to oranges.
JSP and mod_perl aren't really the same kind of technology. In fact, I
wouldnt be suprised if at on point a module called Apache::JSP comes out
on CPAN which compiles JSPs to mod_perl handlers. (There is Apache::ASP)
A better comparission would be JSP vs. Template Toolkit and then perl
vs. Java. If you think you can profit from technologies such as EJB
maybe Java is the way to go. On the other hand, it could very well be
that you are done with the Perl programming well before you got the test
app running on the EJB app server.
malte.exe
------------------------------
Date: Thu, 24 Apr 2003 10:17:47 +0300
From: Marko Vallius <markvalls.spambox@dnainternet.net>
Subject: Re: Parent & Child question:
Message-Id: <rlfkn-pan.ln1@sethlans.mine.nu>
On 23 Apr 2003 20:01:30 -0700, Cao Tran wrote:
> sub Schematic{
>
> $ENV{PATH}= "$HOME/tmp/schematics/";
>
> open(LS,"ls *.ps|");
ls is (usually) in /bin, but you just took everything away from $PATH.
Now sh no longer knows where to find ls, hence the error "sh: ls: not
found". You could try
open(LS,"/bin/ls *.ps|");
and that would work.
But why do you want to set PATH in the first place? If you want to muck
with files in the schematics directory, leave your PATH alone and use
chdir instead:
chdir("$HOME/tmp/schematics") or die "cannot change directory: $!";
> while(<LS>) {
And looking at that, you don't need ls at all. Just say
while(<*.ps>) {
...
No need to open and close LS.
> tr/A-Z/a-z/;
> ($num) = /_[_]+(\w+)\.ps/ ;
> $num = "$2" ."$1" if $num =~ /([a-z])(\d+)/ ;
> rename($name, "$num.ps");
Uh, what are you trying to do? This does not really compute. Your first
pattern match just returns true or false, so the second one does nothing.
Also, I don't see you setting $name anywhere, so what are you renaming?
If I'm guessing correctly, this may be close to what you have in mind:
while(<*.ps>) {
$name = $_;
tr/A-Z/a-z/;
if(/_[_]+(\w+)\.ps/) {
$num = $1;
$num = "$2" ."$1" if $num =~ /([a-z]+)(\d+)/ ;
rename($name, "$num.ps");
}
}
Not without its flaws, but hope this helps.
--
Marko Vallius # http://iki.fi/markvall/
------------------------------
Date: 24 Apr 2003 07:20:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parent & Child question:
Message-Id: <b8838p$2qr$1@mamenchi.zrz.TU-Berlin.DE>
Cao Tran <caotran@sbcglobal.net> wrote in comp.lang.perl.misc:
> Hi,
>
> Here is what I want to do:#! /usr/local/bin/perl
^
That blank shouldn't be there.
Also, you are running without warnings or strict. When a program
gives you trouble, switch them on and correct whatever they point
out. You should do that *before* posting to clpm.
> $None = $#ARGV + 1;
>
> if ($None == "0"){
This is better written as
unless ( @ARGV ) {
> print "USAGE: schematic {PROGRAM_NAME}!\n";
> exit;
> }
>
> $ARGV[0] =~ tr/a-z/A-Z/;
Better:
$ARGV[ 0] = lc $ARGV[ 0];
> $project = $ARGV[0];
You never use the variable "$project".
> $HOME=$ENV{HOME};
>
> Schematic();
>
> sub Schematic{
>
> $ENV{PATH}= "$HOME/tmp/schematics/";
This is the problem you are asking about. After you set the shell
path to ".../tmp/schematics", only commands (executables) in this
directory will be executed by default. All others (including ls)
would have to be fully qualified (/bin/ls).
Scratch that line. It serves no purpose.
> open(LS,"ls *.ps|");
> while(<LS>) {
> tr/A-Z/a-z/;
> ($num) = /_[_]+(\w+)\.ps/ ;
^ ^
What are the "[]" for?
> $num = "$2" ."$1" if $num =~ /([a-z])(\d+)/ ;
> rename($name, "$num.ps");
> }
> close (LS);
> print $ENV{PATH};
> }
>
> When I run this script, I got this message:
> sh: ls: not found
>
> But when I change to sh, and type ls, it work?
Change your path to what it is in the script and try again.
Anno
------------------------------
Date: 24 Apr 2003 08:21:36 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Parent & Child question:
Message-Id: <b886qg$d7l$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Cao Tran <caotran@sbcglobal.net> wrote in comp.lang.perl.misc:
>> Hi,
>>
>> Here is what I want to do:#! /usr/local/bin/perl
> ^
> That blank shouldn't be there.
Not sure whether this is shell-dependent, but at least with Bash they
are totally ok and do no harm.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 24 Apr 2003 08:35:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parent & Child question:
Message-Id: <b887kt$4j2$2@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
>
> > Cao Tran <caotran@sbcglobal.net> wrote in comp.lang.perl.misc:
> >> Hi,
> >>
> >> Here is what I want to do:#! /usr/local/bin/perl
> > ^
> > That blank shouldn't be there.
>
> Not sure whether this is shell-dependent, but at least with Bash they
> are totally ok and do no harm.
That would have to be a feature of the system's "exec". The shell
enters the equation only after exec has found it.
You are right, apparently the blank is accepted by current loaders.
I never noticed, it used to be deadly. In the interest of portability
I'd still avoid it.
Anno
------------------------------
Date: 24 Apr 2003 08:59:05 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Parent & Child question:
Message-Id: <b8890p$fe6$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Also sprach Anno Siegel:
[ #! /bin/executable ]
^
>> > That blank shouldn't be there.
>>
>> Not sure whether this is shell-dependent, but at least with Bash they
>> are totally ok and do no harm.
>
> That would have to be a feature of the system's "exec". The shell
> enters the equation only after exec has found it.
Odd. The bash manual suggests that it's the first program in the
execution chain (if I understand correctly) but a strace(1) shows you
are right.
> You are right, apparently the blank is accepted by current loaders.
> I never noticed, it used to be deadly. In the interest of portability
> I'd still avoid it.
Since it seems to be at the mercy of the libc's exec(2) and not the
shell, this makes sense. So I have to abandon another bad habit, I
guess. :-/
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 24 Apr 2003 09:38:16 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: parsing perl code (audit, summarize, trace)
Message-Id: <3EA7A278.4080509@bbsrc.ac.uk>
Eric Wilhelm wrote:
> Is there a module which allows you to parse perl code?
>
> For example, I would like to write a program which prints all of the
> variables from a list of perl sources (accounting for @array and
> $array[0] only once).
Well if you're running under strict then you might be able to use a
Regex solution based around my / our keywords. Bit of a kludge but it
might get you what you're after.
Otherwise you may be out of luck ("only perl can parse Perl", and all that).
Simon.
------------------------------
Date: Thu, 24 Apr 2003 08:16:06 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Read File, write filename?
Message-Id: <a3Npa.9127$io.304314@iad-read.news.verio.net>
In article <90cdce37.0304231044.58518216@posting.google.com>,
entropy123 <email_entropy123@yahoo.com> wrote:
>I have a directory full of files with various names all ending in
>any_name.old. I need to take information from these files, modify it,
>and save it in a file named any_name.new. Also, and the hardest part
>for me to figure out so far, the first line in any_name.new must be
>any_name.
>
>For example if I had a file named blue_forest.old, I'd want the
>program to make the first line in blue_forest.new to be blue_forest.
@files = glob '*.old'; # Get a list of matching file names
foreach $oldfile (@files) {
($name = $oldfile) =~ s/\.old$//; # Get rid of the extension
$newfile = "$name.new"; # Append new filename extension
# open $oldfile for reading
# open $newfile for writing
# print "$name\n" to the output
# read a line from input file, modify it, write to output file
# repeat until end of file
# close both files
}
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Thu, 24 Apr 2003 04:22:05 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: regular expression question
Message-Id: <NDJpa.108373$MB4.37483786@news4.srv.hcvlny.cv.net>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
news:b86ger$qic$1@nets3.rz.RWTH-Aachen.DE...
--snip--
> number of "y"s larger than 3. If you want to make sure that the string
> has to end on "yyy" you should anchor the pattern:
>
> /FRED(.*)\s.*BARNEY\1$/
or use word boundary if text is not at end of string.
/FRED(.*)\s.*BARNEY\1\b/
Bill
------------------------------
Date: Thu, 24 Apr 2003 04:29:24 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Still Stumped
Message-Id: <3ea767a4.45259403@news.erols.com>
Stop top-posting replies, dammit.
pooba53 <delautenschl@[nospam]wisc.edu> wrote:
: pooba53 wrote:
: > I figured out using the:
: > push ( @{$AllGenes{$gene}}, @range);
: >
: > What I then used to get the unique elements was a chunk of code another
: > gentleman posted a week or so ago that needed a tad bit of modification:
: >
: > while (($key,$aref) = each %AllGenes) {
: > @unique = grep !$seen{$_}++, map @$_, $aref;
: > $count = @unique;
: > print OUTPUT"$key:$count\n";
:
:
: Can you tell me how I can account for $key if one is "CG3038" and
: another is "CG13038"? The algorithm works as long as one key is not a
: subset of another.
That makes no sense.
As hash keys, the strings "CG3038" and "CG13038" have nothing to do
with each other. Your meaning of "as long as one key is not a subset
of another" is not transparent.
A short, complete program with sample data that exhibits the problem
would probably explain it better. Be sure to say how its behavior
differs from what you want; saying "does work" or "doesn't work" is a
waste of good keystrokes.
------------------------------
Date: Thu, 24 Apr 2003 04:10:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <x7n0igo7s1.fsf@mail.sysarch.com>
>>>>> "A" == Agrapha <brian@box201.com> writes:
>>
>> do you realize who you just slammed? look him up on google and see if he
>> ever has helped the perl community.
A> Honestly I am hear to learn and not to banter. If you have the ability
A> to help then please do so. How do I scan thru a flat text file grab a
A> value and count the number of times it occurs. The value looks a lot
A> like "101,4"
if you read you will see i have helped you twice already. i think that
is my limit for you. maybe you might actually learn something.
>>
>> you on the other hand likes to bite the hand that feeds you.
>>
A> and so far you have fed me insults. If you do not have a desire to
A> help others then please feel free to continue this argument by
A> yourself. I formally apologise for requesting help from you, Uri. I'll
A> not make that mistake again.
that's fine. i have only fed back to you the attitude you have shown
us. you seem to want to quote seymour the plant: "FEED ME!!"
A> Are you an important person? I don't know. I suspect if we look
A> with open eyes we can boil the importance off and find a person
A> underneath.
nah, there is a person all over me and very little importance. but i do
know perl a little. now try to learn some and stop asking for free
code.
as for your query here, read the perl FAQ which has answers for counting
stuff
oops, i gave you more help. my bad!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 24 Apr 2003 04:23:12 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <3ea76427.44366338@news.erols.com>
brian@box201.com (Agrapha) wrote:
: > Not if you can avoid it.
: >
: > open F, "file" or die $!;
: > while (<F>) {
: > # each line now in $_ including terminating newline
: > ...
: > }
:
: nice, I think I understand.
:
: my @SELECT = grep (",0 ") 0..#$F;
:
: will load all the failed calls into @SELECT
Yipe.
Your @F (an array) is not the same thing as Tassilo's F (a
filehandle). As well, Perl's grep() is not what you seem to think it
is. The condition ",0 " is not automatically interpreted as a regex.
It's just a string that will always evaluate true.
You might be shooting for something like,
while(<F>) {
push @SELECT, $_ if /,0 /;
}
:
: foreach (@SELECT) {
: $i++;
: }
:
: can count them.
Can, but it's not the Perl way. Using the array in scalar context
will give the number of elements.
$i = @SELECT;
: How would I count how many different types there are if I don't know
: what kinds will be returned? what would I use in place of the "uniq
: -c" command?
See perldoc4, "How can I remove duplicate elements from a list or
array?" It's not quite a direct answer, but the methodology is there.
------------------------------
Date: Thu, 24 Apr 2003 04:25:35 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <3ea76724.45131918@news.erols.com>
tiltonj@erols.com (Jay Tilton) wrote:
: See perldoc4, "How can I remove duplicate elements from a list or
^^^^^^^^
perlfaq4, that is. Ugh.
------------------------------
Date: Wed, 23 Apr 2003 23:14:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbaep5g.22d.tadmc@magna.augustmail.com>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Abigail" == Abigail <abigail@abigail.nl> writes:
>
>Abigail> I'll write your program for you, for $150/hour, 4 hour minimum.
>
> Hey, *I'll* write your program for half that! $75/hr (8 hour minimum)
I'd do it for only $1.25/min, same minimum, if I wasn't so busy
posting unhelpful responses.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 23 Apr 2003 23:11:04 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbaeouo.22d.tadmc@magna.augustmail.com>
Ethan Brown <ethan@draupnir.gso.saic.com> wrote:
> One of the cool (or confusing :-) things about Perl is you get
> different results for different "contexts".
One of the cool or confusing things about natural language is you get
different results for different "contexts".
> For example, there is an
> array context and a scalar context.
For example, there is a plural context and a singular context. :-)
> print @RAWDATA[$#RAWDATA - 4 .. $#RAWDATA]
>
> but that prints things all together. Let's put spaces between the
> elements when we print them out:
>
> print join(' ', @RAWDATA[$#RAWDATA - 4 .. $#RAWDATA])
You can add two characters to the 1st one to get spaces between them:
print "@RAWDATA[$#RAWDATA - 4 .. $#RAWDATA]"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 23 Apr 2003 23:23:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbaepl4.22d.tadmc@magna.augustmail.com>
Agrapha <brian@box201.com> wrote:
[ attribution left out yet again. Please compose your followups properly]
>> Not if you can avoid it.
>>
>> open F, "file" or die $!;
>> while (<F>) {
>> # each line now in $_ including terminating newline
>> ...
>> }
>
> nice, I think I understand.
>
> my @SELECT = grep (",0 ") 0..#$F;
_Perl_ doesn't understand that though, it has a syntax error.
Perhaps you meant
my @SELECT = grep {",0 "} 0..#$F;
instead?
Did you print out the contents of @SELECT when you tried the code?
(you do _not_ understand yet...)
> How would I count how many different types there are if I don't know
> what kinds will be returned? what would I use in place of the "uniq
> -c" command?
perldoc -q duplicate
"How can I remove duplicate elements from a list or array?"
> If there is a way
> to load an array or hash with the error code and then how many times
> it occured? that would be it!
You got it Grasshopper!
my %error_codes;
... # determine code for an input line, put it into $this_code
$error_codes{$this_code}++;
> I guess that is one of the main reasons I didn't learn perl in the
> first place. I get a huge ration everytime I request assistance. Even
> within my own company.
So it isn't just us then.
Maybe it is you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 23 Apr 2003 23:26:07 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbaepqv.22d.tadmc@magna.augustmail.com>
Agrapha <brian@box201.com> wrote:
>>
>> do you realize who you just slammed? look him up on google and see if he
>> ever has helped the perl community.
>
> Honestly I am hear to learn and not to banter. If you
Who "you"?
Please be polite and provide an attribution when you quote someone.
If you cannot do that, then please do not quote someone.
> How do I scan thru a flat text file grab a
> value and count the number of times it occurs.
Use a hash.
>> you on the other hand likes to bite the hand that feeds you.
>>
>
> and so far you have fed me insults.
If you are rude, you can expect rudeness in return.
Many here see/saw you as rude from your very first couple of posts.
> Are you an important person?
You seem to think that _you_ are such a person.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 24 Apr 2003 05:03:16 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbaes0l.4f7.mgjv@verbruggen.comdyn.com.au>
On Wed, 23 Apr 2003 23:23:00 -0500,
Tad McClellan <tadmc@augustmail.com> wrote:
> Agrapha <brian@box201.com> wrote:
>
>
> [ attribution left out yet again. Please compose your followups properly]
>
>
>>> Not if you can avoid it.
>>>
>>> open F, "file" or die $!;
>>> while (<F>) {
>>> # each line now in $_ including terminating newline
>>> ...
>>> }
>>
>> nice, I think I understand.
>>
>> my @SELECT = grep (",0 ") 0..#$F;
>
>
> _Perl_ doesn't understand that though, it has a syntax error.
>
> Perhaps you meant
>
> my @SELECT = grep {",0 "} 0..#$F;
>
> instead?
or maybe even
my @SELECT = grep {",0 "} 0..$#F;
Martien
--
|
Martien Verbruggen | True seekers can always find something to
Trading Post Australia | believe in.
|
------------------------------
Date: Thu, 24 Apr 2003 09:38:03 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <ikbfavoqflgfro0vbcihq0k1qikh366mbe@4ax.com>
Agrapha wrote:
>nice, I think I understand.
>
> my @SELECT = grep (",0 ") 0..#$F;
>
>will load all the failed calls into @SELECT
grep() takes an expression followed by a comma, or a block (curlies)
without comma. You have a bit of a cross between them. Correct Perl
would be either
my @SELECT = grep (",0 "), 0..#$F;
my @SELECT = grep ",0 ", 0..#$F;
or
my @SELECT = grep { ",0 " } 0..#$F;
But I don't think it will do what you want. Your condition is a string,
not a pattern. In fact, it's a string that is true. So it won't filter
a thing.
You want a pattern? Can be done:
/,0 /
but since you're testing on indexes, it won't let anything through.
There's no integer number that contains ",0 " as a string. If @F
contains the strings, then
my @SELECT = grep { $F[$_] =~ /,0 / } 0..#$F;
> foreach (@SELECT) {
> $i++;
> }
>
>can count them.
Eh, you don't need to go through all that trouble. Take an array in
scalar context, and it'll return the count. For example:
$count = @SELECT;
In fact, if you don't care about the values, grep() in scalar context
returns the count of matches:
my $count = grep { $F[$_] =~ /,0 / } 0..#$F;
or, why not,
my $count = grep { /,0 / } @F;
--
Bart.
------------------------------
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 4884
***************************************