[24654] in Perl-Users-Digest
Perl-Users Digest, Issue: 6818 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 14:02:05 2004
Date: Tue, 3 Aug 2004 11:01:16 -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 Tue, 3 Aug 2004 Volume: 10 Number: 6818
Today's topics:
Perl script to replace awk laura.hradowy@mts.NOSPAM.ca
Re: Perl script to replace awk <geoffroy.braem@logidox-computing.com>
Re: Perl script to replace awk <invalid-email@rochester.rr.com>
Re: Perl script to replace awk <tadmc@augustmail.com>
Perl XPath : How to get the value of the attribute? <matrix_calling@yahoo.dot.com>
Re: Perl XPath : How to get the value of the attribute? <mahotrash@yahoo.de>
Re: Perl XPath : How to get the value of the attribute? <matrix_calling@yahoo.dot.com>
Re: Perl XPath : How to get the value of the attribute? <f_point_guillaud@free.fr>
Re: Perl XPath : How to get the value of the attribute? <mahotrash@yahoo.de>
Please help a complete newbie (ZoloftGuy)
Re: Please help a complete newbie <nobull@mail.com>
Re: Please help a complete newbie (ZoloftGuy)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 26 Jul 2004 20:36:43 GMT
From: laura.hradowy@mts.NOSPAM.ca
Subject: Perl script to replace awk
Message-Id: <vXdNc.1760$tK5.9452@news1.mts.net>
I and switching over to perl and need a starting point and need to write a
script that will do the following...
I just need a kick, and should be on my way.
I have a file that is separated by commas, if I print the file out I would
get this...
awk -F, '{print "204"$1","$2","$3}' FILE
The output is
204xxxx001,00 0 05 21,TELN NOT
204xxxx002,00 0 01 30,TELN NOT
204xxxx008,00 0 04 15,TELN NOT
204xxxx013,00 0 02 30,CUST HAS
204xxxx015,00 0 10 22,CUST HAS
I also need to insert data into this line...
204xxxx001,EAST_BLD,ROOM2,00 0 05 21
204xxxx002,EAST_BLD,ROOM2,00 0 01 30
I am just having a difficult time trying to take awk and convert to perl.
I know I can write in bash but I would like to try in perl.
How do I prompt user for input that will insert into the $2, as well as
$3.
Basically I want,
Enter BLD:
User enter is EAST_BLD
Enter room:
User enters in ROOM2
Then the perl script takes that info and inserts these fields into every
line, as well as adding 204 at the begining and dumping the last field.
And here is a trickier question...
How do I do a grep on CUST and then place those lines in a file
------------------------------
Date: Tue, 27 Jul 2004 01:12:25 +0200
From: Geoffroy Braem <geoffroy.braem@logidox-computing.com>
Subject: Re: Perl script to replace awk
Message-Id: <41058FD9.9000605@logidox-computing.com>
laura.hradowy@mts.NOSPAM.ca wrote:
> I and switching over to perl and need a starting point and need to write a
> script that will do the following...
> I just need a kick, and should be on my way.
>
> I have a file that is separated by commas, if I print the file out I would
> get this...
> awk -F, '{print "204"$1","$2","$3}' FILE
>
> The output is
> 204xxxx001,00 0 05 21,TELN NOT
> 204xxxx002,00 0 01 30,TELN NOT
> 204xxxx008,00 0 04 15,TELN NOT
> 204xxxx013,00 0 02 30,CUST HAS
> 204xxxx015,00 0 10 22,CUST HAS
>
> I also need to insert data into this line...
> 204xxxx001,EAST_BLD,ROOM2,00 0 05 21
> 204xxxx002,EAST_BLD,ROOM2,00 0 01 30
>
> I am just having a difficult time trying to take awk and convert to perl.
> I know I can write in bash but I would like to try in perl.
>
> How do I prompt user for input that will insert into the $2, as well as
> $3.
>
> Basically I want,
> Enter BLD:
> User enter is EAST_BLD
>
> Enter room:
> User enters in ROOM2
>
> Then the perl script takes that info and inserts these fields into every
> line, as well as adding 204 at the begining and dumping the last field.
>
> And here is a trickier question...
> How do I do a grep on CUST and then place those lines in a file
>
>
>
Hi Laura,
You could try this
#!/usr/bin/perl
print "Enter BLD:\n";
chomp($input1 = <STDIN>);
print "Enter room:\n";
chomp($input2 = <STDIN>);
open(TMP, "yourdatafile") or die $!;
while(<TMP>){
chomp;
@L = split /,/, $_;
print join(",", $L[0],$input1,$input2,@L[1..$#L]), "\n";
}
--
geoffroy.braem@logidox-computing.com
Logidox Computing
CM (Clearcase) & DataWarehouse(Oracle) consulting, Unix programming
(Java, Perl, Korn Shell).
in Belgium, England, Luxembourg and more.
www.logidox-computing.com
------------------------------
Date: Mon, 26 Jul 2004 22:22:20 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Perl script to replace awk
Message-Id: <41058315.7000307@rochester.rr.com>
laura.hradowy@mts.NOSPAM.ca wrote:
...
> I am just having a difficult time trying to take awk and convert to perl.
> I know I can write in bash but I would like to try in perl.
...
Check out:
perldoc a2p
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Mon, 26 Jul 2004 17:23:44 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl script to replace awk
Message-Id: <slrncgb13g.ppn.tadmc@magna.augustmail.com>
laura.hradowy@mts.NOSPAM.ca <laura.hradowy@mts.NOSPAM.ca> wrote:
> I am just having a difficult time trying to take awk and convert to perl.
Run it through the awk-to-perl translator (a2p) that comes with perl itself.
man a2p
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 29 Jul 2004 18:02:30 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Perl XPath : How to get the value of the attribute?
Message-Id: <re6Oc.22$8H4.41@news.oracle.com>
Hi,
I have the following XML :
<checkIn bug="1111111">
<regression>
</regression>
</checkIn>
How do i get the value "1111111" for bug ?
I am able to get everything under <checkIn> using
my $bug = $xPath->find("/checkIn[\@bug]");
TIA
--
Abhinav
------------------------------
Date: Thu, 29 Jul 2004 14:52:46 +0200
From: Martin Honnen <mahotrash@yahoo.de>
Subject: Re: Perl XPath : How to get the value of the attribute?
Message-Id: <4108f328$1@olaf.komtel.net>
Abhinav wrote:
> I have the following XML :
>
> <checkIn bug="1111111">
> <regression>
> </regression>
> </checkIn>
>
> How do i get the value "1111111" for bug ?
>
> I am able to get everything under <checkIn> using
>
> my $bug = $xPath->find("/checkIn[\@bug]");
I don't use Perl, but the XPath should be
/checkIn/@bug
--
Martin Honnen
http://JavaScript.FAQTs.com/
------------------------------
Date: Thu, 29 Jul 2004 18:36:53 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: Perl XPath : How to get the value of the attribute?
Message-Id: <GK6Oc.23$8H4.79@news.oracle.com>
Martin Honnen wrote:
>
> Abhinav wrote:
>
>
>
>>I have the following XML :
>>
>><checkIn bug="1111111">
>> <regression>
>> </regression>
>></checkIn>
>>
>>How do i get the value "1111111" for bug ?
>>
>>I am able to get everything under <checkIn> using
>>
>>my $bug = $xPath->find("/checkIn[\@bug]");
>
>
> I don't use Perl, but the XPath should be
> /checkIn/@bug
>
Thanks. That Worked !
I guess the extra / allows me to fetch only the node containing the
attribute ?
Any docs (apart from the CPAN XPath docs) which detail these concepts more
clearly ?
TIA
--
Abhinav
------------------------------
Date: Thu, 29 Jul 2004 15:07:09 +0200
From: Franck Guillaud <f_point_guillaud@free.fr>
Subject: Re: Perl XPath : How to get the value of the attribute?
Message-Id: <4108f756$0$29370$626a14ce@news.free.fr>
Abhinav wrote:
>
> Any docs (apart from the CPAN XPath docs) which detail these concepts
> more clearly ?
Google is your friend :
http://www.w3schools.com/xpath/default.asp
And the official W3C reccomendation :
http://www.w3.org/TR/xpath
Franck,e-
>
> TIA
>
> --
>
> Abhinav
------------------------------
Date: Thu, 29 Jul 2004 15:13:27 +0200
From: Martin Honnen <mahotrash@yahoo.de>
Subject: Re: Perl XPath : How to get the value of the attribute?
Message-Id: <4108f801@olaf.komtel.net>
Abhinav wrote:
> Martin Honnen wrote:
>
>>
>> Abhinav wrote:
>>
>>
>>
>>> I have the following XML :
>>>
>>> <checkIn bug="1111111">
>>> <regression>
>>> </regression>
>>> </checkIn>
>>>
>>> How do i get the value "1111111" for bug ?
>>>
>>> I am able to get everything under <checkIn> using
>>>
>>> my $bug = $xPath->find("/checkIn[\@bug]");
>>
>>
>>
>> I don't use Perl, but the XPath should be
>> /checkIn/@bug
>>
>
> I guess the extra / allows me to fetch only the node containing the
> attribute ?
No, it selects the attribute node itself,
/checkIn
selects the <checkIn> root element,
/checkIn/@*
selects all its attribute nodes, and
/checkIn/@bug
selects the attribute with name bug
> Any docs (apart from the CPAN XPath docs) which detail these concepts
> more clearly ?
There is the XPath 1.0 specification:
http://www.w3.org/TR/xpath
And there are tutorials, see
http://www.w3schools.com/xpath/default.asp
for instance.
--
Martin Honnen
http://JavaScript.FAQTs.com/
------------------------------
Date: 29 Jul 2004 13:45:03 -0700
From: zoloftguy@myrealbox.com (ZoloftGuy)
Subject: Please help a complete newbie
Message-Id: <d4376e99.0407291245.2d906ab2@posting.google.com>
The goal is to reboot and or shutdown a Nortel Contivity box with PERL
and the Telnet Script.
use Net::Telnet ();
###Prompt is "$"
$t = new Net::Telnet (Timeout => 30, Prompt => '/[\$]/');
$t->input_log('input.txt');
$t->output_log('output.txt');
$t->open("nortelcontivity");
$t->waitfor('/Login:/');
$t->print("admin");
$t->waitfor('/Password:/');
$t->print("thepassword");
$t->waitfor('/CES\>/');
$t->print("en");
$t->waitfor('/Password:/');
$t->print("thepassword");
$t->print("reload restart");
@output1 = $t->cmd('y');
print @output1;
$t->close;
When I issue the reload restart commmand, this message pops up from
the Contivity: (exactly like this, I pulled this from input log.)
%Proceed with reload? (y/n)
I then do this:
@output1 = $t->cmd('y');
print @output1;
$t->close;
It works, the box reboots, but I get this error:
pattern match read eof at C:\temp\yo.pl line 18
Feel free to flame me, I admit, I don't know what the heck I am doing.
Thanks
------------------------------
Date: 29 Jul 2004 21:49:35 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Please help a complete newbie
Message-Id: <u93c3a35eo.fsf@wcl-l.bham.ac.uk>
zoloftguy@myrealbox.com (ZoloftGuy) writes:
> Subject: Please help a complete newbie
Please but the subject of you post in the Subject of your post.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 3 Aug 2004 05:56:48 -0700
From: zoloftguy@myrealbox.com (ZoloftGuy)
Subject: Re: Please help a complete newbie
Message-Id: <d4376e99.0408030456.12f1fa42@posting.google.com>
Here is the solution, in case anyone needs it. Thanks to Joe Smith,
this was resolved in a previous thread.
I am able to reproduce the error report on Linux using a fake `en`.
Here's what it looks like when using $t->input_log('-');
$t->output_log('-');
linux% perl yo.pl
Red Hat Linux release 9 (Shrike)
login: admin
admin
Password: thepassword
Last login: Sat Jul 31 23:08:00 from localhost
CES>en
en
Password: thepassword
reload restart
y
thepassword
reload restart
y
Password accepted
command is reload restart (y/n)
bin/en: faking a reset by killing parent pid 11655
[1] 11688
logout
pattern match read eof at yo.pl line 18
linux%
> Can anyone tell me what this error means?
Since you did not provide a prompt for $t->cmc('y'), Net::Telnet was
using
the Prompt set in the initial connection, '$'. After sending the 'y',
it
was waiting for a dollar sign, but instead got an eof because the
server
closed the telnet connection during its reset.
If you don't want to see that message, change $t->errmode() just
before cmd().
$t->errmode(sub {die @_ unless $_[0] =~ /eof/}); # Be quiet about
getting eof
@output1 = $t->cmd('y'); # 'reset' causes telnet eof
-Joe
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6818
***************************************