Re: Help Required

2003-11-13 Thread Andrew Gaffney
Amit Sharma wrote:
Hi,
   I have written one cgi script which gets the input from user and
modify one xml file and I got this string  as output
http://prv-arweb3.Test.com/Remedy/servlet/Servlet?URL=http://asharma.Test.co
m/Query1.xml&TURL=http://asharma.Test.com/Remedy1.xsl
Here I am getting modified Query1.xml as input and I have to give this
command in address bar to get the desired result. Could you please help me
to let me know how directly through CGi I can go to the address mentioned
above without copying and pasting in address bar. This address will always
remain the same only the xml file will change.
General Question:

In my cgi script I want to open some site let us suppose
http://www.google.com
The way I know of off the top of my head goes something like this:

use CGI;

my $cgi = new CGI;
print $cgi->header;
print "location.href = 'http://www.google.com';
There is a more correct way to do this using HTTP codes, such as:

print "HTTP/1.0 302 Found\n";
print "Location: www.google.com\n\n";
This could be wrong, though, so someone please correct me.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Help Required

2003-11-14 Thread NYIMI Jose (BMB)
perldoc CGI
See section : GENERATING A REDIRECTION HEADER



GENERATING A REDIRECTION HEADER

print $query->redirect('http://somewhere.else/in/movie/land');

Sometimes you don't want to produce a document yourself, but simply redirect the 
browser elsewhere, perhaps choosing a URL based on the time of day or the identity of 
the user.

The redirect() function redirects the browser to a different URL. If you use 
redirection like this, you should not print out a header as well.

One hint I can offer is that relative links may not work correctly when you generate a 
redirection to another document on your site. This is due to a well-intentioned 
optimization that some servers use. The solution to this is to use the full URL 
(including the http: part) of the document you are redirecting to.

You can also use named arguments:

print $query->redirect(-uri=>'http://somewhere.else/in/movie/land',
   -nph=>1);
The -nph parameter, if set to a true value, will issue the correct headers to work 
with a NPH (no-parse-header) script. This is important to use with certain servers, 
such as Microsoft Internet Explorer, which expect all their scripts to be NPH.



José.
 

-Original Message-
From: Amit Sharma [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 14, 2003 7:01 AM
To: [EMAIL PROTECTED]
Subject: Help Required


Hi,
   I have written one cgi script which gets the input from user and modify one xml 
file and I got this string  as output 
http://prv-arweb3.Test.com/Remedy/servlet/Servlet?URL=http://asharma.Test.co
m/Query1.xml&TURL=http://asharma.Test.com/Remedy1.xsl

Here I am getting modified Query1.xml as input and I have to give this command in 
address bar to get the desired result. Could you please help me to let me know how 
directly through CGi I can go to the address mentioned above without copying and 
pasting in address bar. This address will always remain the same only the xml file 
will change.

General Question:

In my cgi script I want to open some site let us suppose http://www.google.com

How can I do that.

Regards,
Amit.














-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help Required

2003-11-14 Thread Tore Aursand
On Fri, 14 Nov 2003 00:17:29 -0600, Andrew Gaffney wrote:
>> In my cgi script I want to open some site let us suppose
>> http://www.google.com

> use CGI;
> 
> my $cgi = new CGI;
> print $cgi->header;
> print "location.href = 'http://www.google.com';
> 
> There is a more correct way to do this using HTTP codes, such as:
> 
> print "HTTP/1.0 302 Found\n";
> print "Location: www.google.com\n\n";

Not quite "right" CGI.pm-wise, as the CGI module _has_ a redirect()
function;

  use CGI;

  my $cgi = CGI->new();
  print $cgi->redirect( 'http://www.google.com/' );

More information:

  perldoc CGI


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help required

2003-03-30 Thread simran
Have a look at the MIME::Entity module on http://search.cpan.org/

Use that to build your message, and then one of the mail modules, 
or even sendmail to send the message.


On Mon, 2003-03-31 at 16:49, Brijesh Kanderia wrote:
> Hi All,
> 
> I dont have very much idea about perl programing. I have writen a small script which 
> reads the content of one file which keeps on changing daily. and sends the out put 
> to the concerned person thru mail.
> 
> Now what I want is that I dont want the contents. I want this script to send this 
> txt file as an attachment to [EMAIL PROTECTED] now pls tell me how to do this.
> 
> Regds
> Brij
> 
>  
> #!/usr/bin/perl
> 
> sub get_date();
> 
> $SENDMAIL = "/usr/sbin/sendmail";
> $CAT = "/bin/cat";
> $logdir="/root";
> $mailfile = "$logdir/maillog.txt";
> mailto:$emailaddr="[EMAIL PROTECTED];
> 
> get_date();
> 
> sub get_date()
> {
> $DATE   = `date +%Y%m%d`;
> chop ($DATE);
> #$day   = `date +%d`;
> #chop ($day);
> #$hour = `date +%H`;
> #chop ($hour);
> }
> 
> # send mail to whoever concerned
> open (MAIL, "| $SENDMAIL [EMAIL PROTECTED] $emailaddr");
> printf MAIL "Subject: [PI-IN] Satyaki SMTP Maillog Report ($DATE)\n";
> $kitty = `$CAT $mailfile`;
> print MAIL "$kitty\n";
> close(MAIL);
> exit;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help required

2003-03-31 Thread Scott R. Godin
Brijesh Kanderia wrote:

> Hi All,
> 
> I dont have very much idea about perl programing. I have writen a small
> script which reads the content of one file which keeps on changing daily.
> and sends the out put to the concerned person thru mail.
> 
> Now what I want is that I dont want the contents. I want this script to
> send this txt file as an attachment to [EMAIL PROTECTED] now pls tell me how to
> do this.

Take a look at Mail::Mailer from CPAN

You might want to have MIME::Base64 installed as well.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help required with DBI

2004-07-24 Thread David Dorward
On Sat, 2004-07-24 at 19:14, NandKishore.Sagi wrote:

> $data_source = "dbi:DriverName:database_name" ;
>  
> Can't locate DBD/DriverName.pm in

Change "DriveName" to the name of the driver you want to use (e.g.
mysql)

Change "database_name" to the name of the database you want to use.

-- 
David Dorward      


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help Required : Coding Standards

2002-03-27 Thread Jonathan E. Paton

> Just need to know any good docs/web links for Coding
> Standards In PERL. Any pointers are welcome.

Style Guide:
perldoc perlstyle

Writing portable code:
perldoc perlport

Documentation index:
perldoc perl

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help required about NET::TELNET

2005-12-05 Thread vmalik
Hey Mazhar,

I don't know much about perl, but in the $telnet->waitfor method, what does the
weird parameter mean ('/login: $/i')? I thought that $ means a scalar variable
in perl. What do the forward slashes do here? Some sort of regular expression??

Vishal


Quoting Mazhar <[EMAIL PROTECTED]>:

> Hi Folks,
> I have installed the module NET::TELNET from CPAN and when i try to
> execute the below simple pgm,
> 
> ---
> use Net::Telnet;
> $telnet = new Net::Telnet ( Timeout=>100,Errmode=>'die');
> $telnet->open('202.177.129.37');
>  $telnet->waitfor('/login: $/i');
>  $telnet->print('root');
>  $telnet->waitfor('/password: $/i');
>  $telnet->print('[EMAIL PROTECTED]');
>  print $telnet->cmd('who');
> 
> --
> The Output of the above program is
> pattern match read eof at prog.pl line 12
> 
> 
> Please help me out folks as where may be the problem
> 
> Regards
> Mazhar
> 





This mail sent through www.mywaterloo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help required about NET::TELNET

2005-12-05 Thread Stephen Kratzer
Mazhar,

try:
$telnet->waitfor(Match => '/login: $/i');
and
$telnet->waitfor(Match => '/password: $/i');

Vishal,

Right, you want to wait for the device to return something that will match the 
expression between the slashes. In that example, you'd be waiting for the 
device to return a login prompt ending with a space and you'd ignore 
capitalization.

On Monday 05 December 2005 10:19, [EMAIL PROTECTED] wrote:
> Hey Mazhar,
>
> I don't know much about perl, but in the $telnet->waitfor method, what does
> the weird parameter mean ('/login: $/i')? I thought that $ means a scalar
> variable in perl. What do the forward slashes do here? Some sort of regular
> expression??
>
> Vishal
>
> Quoting Mazhar <[EMAIL PROTECTED]>:
> > Hi Folks,
> > I have installed the module NET::TELNET from CPAN and when i try to
> > execute the below simple pgm,
> >
> > ---
> > use Net::Telnet;
> > $telnet = new Net::Telnet ( Timeout=>100,Errmode=>'die');
> > $telnet->open('202.177.129.37');
> >  $telnet->waitfor('/login: $/i');
> >  $telnet->print('root');
> >  $telnet->waitfor('/password: $/i');
> >  $telnet->print('[EMAIL PROTECTED]');
> >  print $telnet->cmd('who');
> >
> > -
> >- The Output of the above program is
> > pattern match read eof at prog.pl line 12
> >
> >
> > Please help me out folks as where may be the problem
> >
> > Regards
> > Mazhar
>
> 
> This mail sent through www.mywaterloo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: help required regarding Win32::OLE

2006-02-09 Thread Toby Stuart


> -Original Message-
> From: a b [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 9 February 2006 11:47 PM
> To: libwin32@perl.org; beginners@perl.org
> Subject: help required regarding Win32::OLE
> 
> 
> Hello all perl gurus,
> 
> i'm  sticking out with the issue of changing configuration of 
> IIS server
> running on remote machine.
> 
> i want to know the possibility of doing that using Win32::OLE module.
> so, far i am unable to do that.
> 
> Can any body send me some tutorials / docs regarding IIS server
> configuration/Management using Win32::OLE.
> 
> Thanks and regards
> a b
> 

many moons ago i wrote a module to do this but alas i have misplaced it :(

anyhoo google knows all ...



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/333c4be3-bb62-437b-85be-3b3e8207c8c1.asp

http://www.issociate.de/board/goto/185241/Perl_and_IIS_ADSI_(WAS:_more_info_on_Win32::OLE_stuff?).html

http://www.codecomments.com/archive235-2004-11-328926.html

http://groups.google.com.au/group/comp.lang.perl.misc/browse_thread/thread/194a1f9b97cc9483/1a12311a1e67e1e8%231a12311a1e67e1e8?sa=X&oi=groupsr&start=0&num=3



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Help Required on the Script

2006-04-05 Thread Raymond Raj
> -Original Message-
> From: Mazhar [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 05, 2006 12:16 PM
> To: beginners@perl.org
> Subject: Help Required on the Script
> 
> 
> Hi Guyz,
> i am writin a script to automate the command 
> snmpwalk by reading
> the contents of a file. Below is the snippet
> 
> $file_name="somefile.txt";
> 
> open(FILE,"< $file_name");
> 
> while()
> {
> my $ip;
> my $comm_string;
> ($ip,$comm_string)=split(",",$_);
> $tempRNA=qw("snmpwalk -t 1 -r 1 $ip $comm_string 
> .1.3.6.1.2.1.1.5 >
> RNA$ip.txt");
> 

may be you want qq not qw. qw returns list.

for more details about qw or qq see perlop.
perldoc perlop




Confidentiality Notice: This transmittal is a confidential communication.  If 
you are not the intended recipient, you are hereby notified that you have 
received this transmittal in error and that any review, dissemination, 
distribution or copying of this transmittal is strictly prohibited. If you have 
received this communication in error, please notify this office immediately by 
reply and immediately delete this message and all of its attachments, if any.

Re: Help Required on the Script

2006-04-05 Thread Jaime Murillo
On Tuesday 04 April 2006 23:46, Mazhar wrote:
> Hi Guyz,

Hi Mazhar,

> i am writin a script to automate the command snmpwalk by
> reading the contents of a file. Below is the snippet
>
> $file_name="somefile.txt";
>
> open(FILE,"< $file_name");
>
> while()
> {
> my $ip;
> my $comm_string;
> ($ip,$comm_string)=split(",",$_);
> $tempRNA=qw("snmpwalk -t 1 -r 1 $ip $comm_string .1.3.6.1.2.1.1.5 >
> RNA$ip.txt");
>

This might work for you

#!/usr/bin/perl
use strict;
use warnings;

my $file_name = "somefile.txt";

open(FILE, "< $file_name") or die("Error opening $file_name: $!\n");

while()
{
chomp;
my ($ip, $comm_string) = split ",";
my $tempRNA = "snmpwalk -t 1 -r 1 $ip $comm_string .1.3.6.1.2.1.1.5 > 
RNA$ip.txt";

print "$tempRNA\n";
}

Good luck

> *** I am facing the problem in the above code where in i have to pass all
> the information to the variable $tempRNA and then execute the same in the
> System ($tempRNA)
>
> When i try to print the value in the variable $tempRNA i am getting the
> value printed only RNAxx.xxx.xxx..txt
>
> Please help me out and Thanks is Advance
>
> Regards
> Mazhar

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help Required on the Script

2006-04-05 Thread Mazhar
thanks Jamie.

It is Working.

Regards
Mazhar

On 4/5/06, Jaime Murillo <[EMAIL PROTECTED]> wrote:
>
> On Tuesday 04 April 2006 23:46, Mazhar wrote:
> > Hi Guyz,
>
> Hi Mazhar,
>
> > i am writin a script to automate the command snmpwalk by
> > reading the contents of a file. Below is the snippet
> >
> > $file_name="somefile.txt";
> >
> > open(FILE,"< $file_name");
> >
> > while()
> > {
> > my $ip;
> > my $comm_string;
> > ($ip,$comm_string)=split(",",$_);
> > $tempRNA=qw("snmpwalk -t 1 -r 1 $ip $comm_string
> .1.3.6.1.2.1.1.5 >
> > RNA$ip.txt");
> >
>
> This might work for you
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $file_name = "somefile.txt";
>
> open(FILE, "< $file_name") or die("Error opening $file_name: $!\n");
>
> while()
> {
> chomp;
> my ($ip, $comm_string) = split ",";
> my $tempRNA = "snmpwalk -t 1 -r 1 $ip $comm_string
> .1.3.6.1.2.1.1.5 >
> RNA$ip.txt";
>
> print "$tempRNA\n";
> }
>
> Good luck
>
> > *** I am facing the problem in the above code where in i have to pass
> all
> > the information to the variable $tempRNA and then execute the same in
> the
> > System ($tempRNA)
> >
> > When i try to print the value in the variable $tempRNA i am getting the
> > value printed only RNAxx.xxx.xxx..txt
> >
> > Please help me out and Thanks is Advance
> >
> > Regards
> > Mazhar
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


Re: Help Required on the Script

2006-04-06 Thread Mazhar
Thank you giyz for the help i require one more help from yourside. i have
one more code where in i am getting error on print of a value of a variable,


below is the code

#!/usr/bin/perl -w
use strict;
use warnings;

my $string="[EMAIL PROTECTED]";

print $string;

On executing the above i get the below error...


In string, @04 now must be written as [EMAIL PROTECTED] at regular.pl line 5, 
near "
[EMAIL PROTECTED]"
Execution of regular.pl aborted due to compilation errors.


Your help is required

Regards
Mazhar

On 4/5/06, Jaime Murillo <[EMAIL PROTECTED]> wrote:
>
> On Tuesday 04 April 2006 23:46, Mazhar wrote:
> > Hi Guyz,
>
> Hi Mazhar,
>
> > i am writin a script to automate the command snmpwalk by
> > reading the contents of a file. Below is the snippet
> >
> > $file_name="somefile.txt";
> >
> > open(FILE,"< $file_name");
> >
> > while()
> > {
> > my $ip;
> > my $comm_string;
> > ($ip,$comm_string)=split(",",$_);
> > $tempRNA=qw("snmpwalk -t 1 -r 1 $ip $comm_string
> .1.3.6.1.2.1.1.5 >
> > RNA$ip.txt");
> >
>
> This might work for you
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $file_name = "somefile.txt";
>
> open(FILE, "< $file_name") or die("Error opening $file_name: $!\n");
>
> while()
> {
> chomp;
> my ($ip, $comm_string) = split ",";
> my $tempRNA = "snmpwalk -t 1 -r 1 $ip $comm_string
> .1.3.6.1.2.1.1.5 >
> RNA$ip.txt";
>
> print "$tempRNA\n";
> }
>
> Good luck
>
> > *** I am facing the problem in the above code where in i have to pass
> all
> > the information to the variable $tempRNA and then execute the same in
> the
> > System ($tempRNA)
> >
> > When i try to print the value in the variable $tempRNA i am getting the
> > value printed only RNAxx.xxx.xxx..txt
> >
> > Please help me out and Thanks is Advance
> >
> > Regards
> > Mazhar
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


Re: Help Required on the Script

2006-04-06 Thread swayam panda

Hi Mazhar,

 You have to escape @ sysmbol .Inside double quote perl 
will interpolate the value of @ and it will think @04 is an array

so
try
#!/usr/bin/perl -w
use strict;
use warnings;

my $string="[EMAIL PROTECTED]";

print $string;
Correct me if i am wrong
Thanks
Swayam



- Original Message - 
From: "Mazhar" <[EMAIL PROTECTED]>

To: "Jaime Murillo" <[EMAIL PROTECTED]>
Cc: 
Sent: Thursday, April 06, 2006 2:41 PM
Subject: Re: Help Required on the Script


Thank you giyz for the help i require one more help from yourside. i have
one more code where in i am getting error on print of a value of a variable,


below is the code

#!/usr/bin/perl -w
use strict;
use warnings;

my $string="[EMAIL PROTECTED]";

print $string;

On executing the above i get the below error...


In string, @04 now must be written as [EMAIL PROTECTED] at regular.pl line 5, near 
"
[EMAIL PROTECTED]"
Execution of regular.pl aborted due to compilation errors.


Your help is required

Regards
Mazhar

On 4/5/06, Jaime Murillo <[EMAIL PROTECTED]> wrote:


On Tuesday 04 April 2006 23:46, Mazhar wrote:
> Hi Guyz,

Hi Mazhar,

> i am writin a script to automate the command snmpwalk by
> reading the contents of a file. Below is the snippet
>
> $file_name="somefile.txt";
>
> open(FILE,"< $file_name");
>
> while()
> {
> my $ip;
> my $comm_string;
> ($ip,$comm_string)=split(",",$_);
> $tempRNA=qw("snmpwalk -t 1 -r 1 $ip $comm_string
.1.3.6.1.2.1.1.5 >
> RNA$ip.txt");
>

This might work for you

#!/usr/bin/perl
use strict;
use warnings;

my $file_name = "somefile.txt";

open(FILE, "< $file_name") or die("Error opening $file_name: $!\n");

while()
{
chomp;
my ($ip, $comm_string) = split ",";
my $tempRNA = "snmpwalk -t 1 -r 1 $ip $comm_string
.1.3.6.1.2.1.1.5 >
RNA$ip.txt";

print "$tempRNA\n";
}

Good luck

> *** I am facing the problem in the above code where in i have to pass
all
> the information to the variable $tempRNA and then execute the same in
the
> System ($tempRNA)
>
> When i try to print the value in the variable $tempRNA i am getting the
> value printed only RNAxx.xxx.xxx..txt
>
> Please help me out and Thanks is Advance
>
> Regards
> Mazhar

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Help Required on the Script

2006-04-06 Thread Raymond Raj
> -Original Message-
> From: Mazhar [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 06, 2006 2:41 PM
> To: Jaime Murillo
> Cc: beginners@perl.org
> Subject: Re: Help Required on the Script
>
>
> Thank you giyz for the help i require one more help from
> yourside. i have
> one more code where in i am getting error on print of a value
> of a variable,
>
>
> below is the code
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
>
> my $string="[EMAIL PROTECTED]";
>
> print $string;
>


put string into single quotes, double quotes allow variable interpolation so
perl think @04 as some variable.
 my $string='[EMAIL PROTECTED]'; #will work
or you can use  just like below
my $string="[EMAIL PROTECTED]"; #not recommended





Confidentiality Notice: This transmittal is a confidential communication.  If 
you are not the intended recipient, you are hereby notified that you have 
received this transmittal in error and that any review, dissemination, 
distribution or copying of this transmittal is strictly prohibited. If you have 
received this communication in error, please notify this office immediately by 
reply and immediately delete this message and all of its attachments, if any.

Re: Help Required on the Script

2006-04-06 Thread Mazhar
thanks Raymond for the help it works,
and what do u mean by variable interpolation

Regards
Mazhar

On 4/6/06, Raymond Raj <[EMAIL PROTECTED]> wrote:
>
> > -Original Message-
> > From: Mazhar [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, April 06, 2006 2:41 PM
> > To: Jaime Murillo
> > Cc: beginners@perl.org
> > Subject: Re: Help Required on the Script
> >
> >
> > Thank you giyz for the help i require one more help from
> > yourside. i have
> > one more code where in i am getting error on print of a value
> > of a variable,
> >
> >
> > below is the code
> >
> > #!/usr/bin/perl -w
> > use strict;
> > use warnings;
> >
> > my $string="[EMAIL PROTECTED]";
> >
> > print $string;
> >
>
>
> put string into single quotes, double quotes allow variable interpolation
> so
> perl think @04 as some variable.
> my $string='[EMAIL PROTECTED]'; #will work
> or you can use  just like below
> my $string="[EMAIL PROTECTED]"; #not recommended
>
>
>
>
>
> Confidentiality Notice: This transmittal is a confidential
> communication.  If you are not the intended recipient, you are hereby
> notified that you have received this transmittal in error and that any
> review, dissemination, distribution or copying of this transmittal is
> strictly prohibited. If you have received this communication in error,
> please notify this office immediately by reply and immediately delete this
> message and all of its attachments, if any.


RE: Help Required on the Script

2006-04-06 Thread Raymond Raj
> -Original Message-
> From: Mazhar [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 06, 2006 3:19 PM
> To: [EMAIL PROTECTED]
> Cc: beginners@perl.org
> Subject: Re: Help Required on the Script
>
>
> thanks Raymond for the help it works,
> and what do u mean by variable interpolation


may be i don't know how to explain "variable interpolation", why not try in
google? or some one else from this group will explain you

Thanks


>
> Regards
> Mazhar
>





> On 4/6/06, Raymond Raj <[EMAIL PROTECTED]> wrote:
> >
> > > -Original Message-
> > > From: Mazhar [mailto:[EMAIL PROTECTED]
> > > Sent: Thursday, April 06, 2006 2:41 PM
> > > To: Jaime Murillo
> > > Cc: beginners@perl.org
> > > Subject: Re: Help Required on the Script
> > >
> > >
> > > Thank you giyz for the help i require one more help from
> > > yourside. i have
> > > one more code where in i am getting error on print of a value
> > > of a variable,
> > >
> > >
> > > below is the code
> > >
> > > #!/usr/bin/perl -w
> > > use strict;
> > > use warnings;
> > >
> > > my $string="[EMAIL PROTECTED]";
> > >
> > > print $string;
> > >
> >
> >
> > put string into single quotes, double quotes allow variable
> interpolation
> > so
> > perl think @04 as some variable.
> > my $string='[EMAIL PROTECTED]'; #will work
> > or you can use  just like below
> > my $string="[EMAIL PROTECTED]"; #not recommended
> >
> >
> >
> >
> >
> > Confidentiality Notice: This transmittal is a confidential
> > communication.  If you are not the intended recipient, you
> are hereby
> > notified that you have received this transmittal in error
> and that any
> > review, dissemination, distribution or copying of this
> transmittal is
> > strictly prohibited. If you have received this
> communication in error,
> > please notify this office immediately by reply and
> immediately delete this
> > message and all of its attachments, if any.
>





Confidentiality Notice: This transmittal is a confidential communication.  If 
you are not the intended recipient, you are hereby notified that you have 
received this transmittal in error and that any review, dissemination, 
distribution or copying of this transmittal is strictly prohibited. If you have 
received this communication in error, please notify this office immediately by 
reply and immediately delete this message and all of its attachments, if any.

Re: Help Required - Search and Replace

2002-03-21 Thread Patrice Boisieau


Try this algorithm :



>From: Rajanikanth Dandamudi <[EMAIL PROTECTED]>
>To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
>Subject: Help Required - Search and Replace
>Date: Thu, 21 Mar 2002 10:55:41 +0530
>
>All,
>
>I have a one big text file and also I have some set of strings to be
>replaced by another set of strings. Currently, I am reading each line of
>the file, and replacing one set of strings by another set of strings,
>one after another. Is there any efficient way of doing this? The data is
>so huge that this job takes around 7Hrs of total time on Sun Ultra 10.
>Is there any way of efficiently doing this? Thanks in advance.
>
>Thanks and Regards,
>D.Rajanikanth


_
MSN Photos est le moyen le plus simple de partager, modifier et imprimer vos 
photos préférées. http://photos.msn.fr/Support/WorldWide.aspx


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Patrice Boisieau


Try this algorithm :



>From: Rajanikanth Dandamudi <[EMAIL PROTECTED]>
>To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
>Subject: Help Required - Search and Replace
>Date: Thu, 21 Mar 2002 10:55:41 +0530
>
>All,
>
>I have a one big text file and also I have some set of strings to be
>replaced by another set of strings. Currently, I am reading each line of
>the file, and replacing one set of strings by another set of strings,
>one after another. Is there any efficient way of doing this? The data is
>so huge that this job takes around 7Hrs of total time on Sun Ultra 10.
>Is there any way of efficiently doing this? Thanks in advance.
>
>Thanks and Regards,
>D.Rajanikanth


_
Discutez en ligne avec vos amis, essayez MSN Messenger : 
http://messenger.msn.fr


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Patrice Boisieau


Try this algorithm :

Read the file (if you have sufficient memory to load it)
Replace in each ligne
Write the new lines

P. Boisieau

>From: Rajanikanth Dandamudi <[EMAIL PROTECTED]>
>To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
>Subject: Help Required - Search and Replace
>Date: Thu, 21 Mar 2002 10:55:41 +0530
>
>All,
>
>I have a one big text file and also I have some set of strings to be
>replaced by another set of strings. Currently, I am reading each line of
>the file, and replacing one set of strings by another set of strings,
>one after another. Is there any efficient way of doing this? The data is
>so huge that this job takes around 7Hrs of total time on Sun Ultra 10.
>Is there any way of efficiently doing this? Thanks in advance.
>
>Thanks and Regards,
>D.Rajanikanth


_
Téléchargez MSN Explorer gratuitement à l'adresse 
http://explorer.msn.fr/intl.asp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Michael Stidham

my $new_file;
open(FILE,') {
  $line=~s/WORD_TO_REPLACE/REPLACEMENT_WORD/g;
  $new_file.=$line;
}
close(FILE);
open(FILE,'>new_file.txt') or die "Can't write new_file.txt: $!\n";
print FILE $new_file;
close(FILE)

I do something like this. Hope it helps

>- Original Message -
>From: "Rajanikanth Dandamudi" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Thursday, March 21, 2002 1:25 PM
>Subject: Help Required - Search and Replace
>
>
> > All,
> >
> > I have a one big text file and also I have some set of strings to be
> > replaced by another set of strings. Currently, I am reading each line of
> > the file, and replacing one set of strings by another set of strings,
> > one after another. Is there any efficient way of doing this? The data is
> > so huge that this job takes around 7Hrs of total time on Sun Ultra 10.
> > Is there any way of efficiently doing this? Thanks in advance.
> >
> > Thanks and Regards,
> > D.Rajanikanth
> >
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>


_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Jonathan E. Paton

> I have a one big text file and also I have some
> set of strings to be replaced by another set of
> strings. Currently, I am reading each line of
> the file, and replacing one set of strings by
> another set of strings, one after another. Is
> there any efficient way of doing this?  The data
> is so huge that this job takes around 7Hrs of
> total time on Sun Ultra 10.

What is the size of the input file?  Gigabytes?

I presume you are following the suggestions of
reading from one file, and writing the
modifications to another - that seemed obvious.

7 hours, however, seems a rather long time.
May I ask if those sets of strings changes from
one execution to another?  E.g.

my $word = "WORD";

while (<>) {
s/$word/lie/g; #Slow
}

is slow because that $word forces the regex to
be recompiled each time through.  The best way
to solve this problem is to create a Perl
script on the fly and run using eval $script;

I hope this helps,

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Jeff 'japhy' Pinyan

On Mar 21, Jonathan E. Paton said:

>> I have a one big text file and also I have some
>> set of strings to be replaced by another set of
>> strings. Currently, I am reading each line of
>> the file, and replacing one set of strings by
>> another set of strings, one after another. Is
>> there any efficient way of doing this?  The data
>> is so huge that this job takes around 7Hrs of
>> total time on Sun Ultra 10.
>
>my $word = "WORD";
>
>while (<>) {
>s/$word/lie/g; #Slow
>}
>
>is slow because that $word forces the regex to
>be recompiled each time through.  The best way
>to solve this problem is to create a Perl
>script on the fly and run using eval $script;

Not true about that regex.  Here is a comparison:

  for $w (@words) {
for (@lines) {
  if (/$w/) { ... }
}
  }

vs.

  for (@lines) {
for $w (@words) {
  if (/$w/) { ... }
}
  }

The second can be much slower than the first.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required - Search and Replace

2002-03-21 Thread Jonathan E. Paton

> >my $word = "WORD";
> >
> >while (<>) {
> >s/$word/lie/g; #Slow
> >}
> >
> >is slow because that $word forces the regex to
> >be recompiled each time through.  The best way
> >to solve this problem is to create a Perl
> >script on the fly and run using eval $script;
> 
> Not true about that regex.  Here is a comparison:
> [snip]

True Japhy.  AFAIK Perl would evaluate $word each
time in other to check that the regex is unchanged.
That doesn't count as the really slow action of
recompiling, but is still additional time...

that is, unless the JIT optimiser pulls that case
out.  Does it?

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help Required on the Below Script

2006-06-14 Thread Prabu Ayyappan

On 6/14/06, Mazhar <[EMAIL PROTECTED]> wrote:


Hello,

I am writing perl on windows installing Activestate Perl and the code is
reading a text file and processing it,

the code what i use is...

##
use strict;
use warnings;

my $file_name=".txt";

open(FILE,"$file_name") || die "Not been Accessed";
while () {
  print $_ "\n";

}



I get a wired output when i run the above code..

*Useless use of a constant in void context at gathercheck.pl line 9.
Can't use string ("2006/06/11 00:00:02 (7):(4480) t") as a symbol ref
while
"str
ict refs" in use at gathercheck.pl line 11,  line 1.*

Some lines in the imput file is like the below,

2006/06/11 00:00:02 (7):(4480) tc1a-pgw-1m, Waiting for another gather on
REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M
2006/06/11 00:00:02 (7):(5852) tc1a-pgw-1m, Waiting for another gather on
REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M
2006/06/11 00:00:02 (7):(4492) tc1a-pgw-1m, Waiting for another gather on
REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M

Please help me out on the above as i am not able to understand the error
output..

Regards

Mazhar




Hope this wil  work (place a dot before \n(concatenation) in the print)

#!/usr/bin/perl
use strict;
use warnings;
my $file_name="XXX.txt";
open(FILE,"$file_name") || die "Not been Accessed";
while () {
print $_."\n"; #place a dot before \n(concatenation)
}


--
Prabu M A


Re: Help Required on the Below Script

2006-06-14 Thread Mr. Shawn H. Corey
On Wed, 2006-14-06 at 15:59 +0400, Mazhar wrote:
> Hello,
> 
> I am writing perl on windows installing Activestate Perl and the code is
> reading a text file and processing it,
> 
> the code what i use is...
> 
> ##
> use strict;
> use warnings;
> 
> my $file_name=".txt";
> 
> open(FILE,"$file_name") || die "Not been Accessed";
> while () {
>   print $_ "\n";

  print $_, "\n";  # print double-spaced
  # See `perldoc -f print`

> 
> }
> 
> 
> 
> I get a wired output when i run the above code..
> 
> *Useless use of a constant in void context at gathercheck.pl line 9.
> Can't use string ("2006/06/11 00:00:02 (7):(4480) t") as a symbol ref while
> "str
> ict refs" in use at gathercheck.pl line 11,  line 1.*
> 
> Some lines in the imput file is like the below,
> 
> 2006/06/11 00:00:02 (7):(4480) tc1a-pgw-1m, Waiting for another gather on
> REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M
> 2006/06/11 00:00:02 (7):(5852) tc1a-pgw-1m, Waiting for another gather on
> REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M
> 2006/06/11 00:00:02 (7):(4492) tc1a-pgw-1m, Waiting for another gather on
> REPORTER_GATHER_MUTEX_FOR_TC1A_PGW_1M
> 
> Please help me out on the above as i am not able to understand the error
> output..


-- 
__END__

Just my 0.0002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help Required on the Below Script

2006-06-14 Thread John W. Krahn
Mazhar wrote:
> Hello,

Hello,

> I am writing perl on windows installing Activestate Perl and the code is
> reading a text file and processing it,
> 
> the code what i use is...
> 
> ##
> use strict;
> use warnings;
> 
> my $file_name=".txt";
> 
> open(FILE,"$file_name") || die "Not been Accessed";
> while () {
>  print $_ "\n";

print() is interpreting the value in $_ as a filehandle.  You need to either
supply a list to print:

print $_, "\n";

Or a single string:

print "$_\n";

Or alternately set the output record separator:

$\ = "\n";
while (  ) {
print;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help Required on the Below Script

2006-06-14 Thread Mazhar

Thanks everybody for the support..

it is working fine..

Regards
Mazhar


On 6/14/06, John W. Krahn <[EMAIL PROTECTED]> wrote:


Mazhar wrote:
> Hello,

Hello,

> I am writing perl on windows installing Activestate Perl and the code is
> reading a text file and processing it,
>
> the code what i use is...
>
> ##
> use strict;
> use warnings;
>
> my $file_name=".txt";
>
> open(FILE,"$file_name") || die "Not been Accessed";
> while () {
>  print $_ "\n";

print() is interpreting the value in $_ as a filehandle.  You need to
either
supply a list to print:

   print $_, "\n";

Or a single string:

   print "$_\n";

Or alternately set the output record separator:

$\ = "\n";
while (  ) {
   print;



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 





Re: Help Required on the Below Script

2006-06-14 Thread JupiterHost.Net

Hello,


use strict;
use warnings;



Excellent use of those :)


my $file_name=".txt";

open(FILE,"$file_name") || die "Not been Accessed";


Good that you checked for failure, why not also report the error ...

Also, don't double quote strings that have nothing to be interpolated or 
are just a single variable.


open my $file_fh, $file_name or die "Open $file_name failed: $!";


while () {
 print $_ "\n";

}


You're trying to print a newline to the variable $_ which is just wonky :)

while(<$file_fh>) {
print "$_\n"; # or way more ugly and convolutedly: print $_ . "\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help required.....about string/text manipulation

2003-06-13 Thread Rob Dixon
Mohit_jain01 wrote:
> Hi,
>
> I am facing a problem with text file manipulation with Perl.
>
> I have a file with over 2 lac lines of data.
> I need to find the duplicates(strings) in the file and copy those records into 
> another file.
>
> Is there a function/module  in Perl by which I can read the duplicates in a file at 
> one go and print them
> on to another file.

Hi.

Before we can help you we need to know a little more of your problem.

Are you looking for duplicate lines in the file, or duplicate strings defined
in some other way? How big is the file you want to read (how many lines
or strings do you want to compare)?

There are modules which will help you write your program, but exactly
how you go about it depends on the details of your problem.

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Help required.....about string/text manipulation

2003-06-13 Thread Mohit_Jain01
Hi Rob,
I have a big file containing about 20 lines. This file basically contains some 
records. A sample of the file is as given below:
 
dn: cn=1148734,ou=Employees,dc=jci,dc=com

displayname: Herek, Moriah L

jdirlastfourssn: 2888

dn: cn=1148735,ou=Employees,dc=jci,dc=com

displayname: Pelletier, Michael J

jdirlastfourssn: 8719

uid: cpellem

dn: cn=1148736,ou=Employees,dc=jci,dc=com

displayname: Manimanakis, Aris N

jdirlastfourssn: 0366

dn: cn=1148738,ou=Employees,dc=jci,dc=com

displayname: Bernardini, James A

jdirlastfourssn: 8540

dn: cn=1148739,ou=Employees,dc=jci,dc=com

displayname: Steyvers, Robert L

jdirlastfourssn: 8634

dn: cn=1148740,ou=Employees,dc=jci,dc=com

displayname: Vest, Elizabeth G

jdirlastfourssn: 7487

What I need to do is:

1. Take the first entry and get the value of the display name and jdirlastfourssn 
attribute.

2. Check whether there is another record with the same display name attribute 
value.(There cud be multiple records)

 3. If so then extract both record and write them into another file.

 4. Delete these duplicate records from the parent file. 

5. Do that for all records.

Please see if you can help me in doing this.

Regards,

Mohit

-Original Message- 
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Sat 6/14/2003 3:39 AM 
To: [EMAIL PROTECTED] 
Cc: 
Subject: Re: Help required.about string/text manipulation



Mohit_jain01 wrote:
> Hi,
>
> I am facing a problem with text file manipulation with Perl.
>
> I have a file with over 2 lac lines of data.
> I need to find the duplicates(strings) in the file and copy those records 
into another file.
>
> Is there a function/module  in Perl by which I can read the duplicates in a 
file at one go and print them
> on to another file.

Hi.

Before we can help you we need to know a little more of your problem.

Are you looking for duplicate lines in the file, or duplicate strings defined
in some other way? How big is the file you want to read (how many lines
or strings do you want to compare)?

There are modules which will help you write your program, but exactly
how you go about it depends on the details of your problem.

Rob




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





Re: Help required.....about string/text manipulation

2003-06-14 Thread Rob Dixon
Mohit_jain01 wrote:
>
> > From: Rob Dixon
> >
> > Mohit_jain01 wrote:
> > >
> > > I am facing a problem with text file manipulation with Perl.
> > >
> > > I have a file with over 2 lac lines of data.
> > > I need to find the duplicates(strings) in the file and copy those records into 
> > > another file.
> > >
> > > Is there a function/module  in Perl by which I can read the duplicates in a file 
> > > at one go and print them
> > > on to another file.
> >
> > Before we can help you we need to know a little more of your problem.
> >
> > Are you looking for duplicate lines in the file, or duplicate strings defined
> > in some other way? How big is the file you want to read (how many lines
> > or strings do you want to compare)?
> >
> > There are modules which will help you write your program, but exactly
> > how you go about it depends on the details of your problem.
>
> I have a big file containing about 20 lines. This file basically contains some 
> records. A sample of the file is as given
> below:
>
> dn: cn=1148734,ou=Employees,dc=jci,dc=com
>
> displayname: Herek, Moriah L
>
> jdirlastfourssn: 2888
>
> dn: cn=1148735,ou=Employees,dc=jci,dc=com
>
> displayname: Pelletier, Michael J
>
> jdirlastfourssn: 8719
>
> uid: cpellem
>
[snip data]
>
> What I need to do is:
>
> 1. Take the first entry and get the value of the display name and jdirlastfourssn 
> attribute.
>
> 2. Check whether there is another record with the same display name attribute value.
>(There cud be multiple records)
>
>  3. If so then extract both record and write them into another file.
>
>  4. Delete these duplicate records from the parent file.
>
> 5. Do that for all records.
>

I'm not clear whether you mean 200K lines or 200K records (which seem to be mostly
6 lines each except for 'Pelletier, Michael J' which has an additional pair of
lines for a 'uid' value. But, even if it were 200K records at about 100 characters
each this would be 20Mb, which is well within the capacity of all but the smallest
computers these days. This problem is far easier with all the data in memory, so
I'll go that way, and if you find it's not working or is too slow we'll think again.

OK, so let me rewrite your algorithm a little.

- Read all records into memory
- While there are records left
-   calculate a 'key' from the display name and serial number
-   find all records in the data with a matching key
-   if there was only one then print it to parent file, else print them to file 2
-   delete them from the list

>From the top:


"Read in all of the records"

It looks like all the information starts with a line beginning with 'dn:'. If this
is wrong we'll have to change it.

  my @records;

  while () {
push @records, '' if /^dn:\s+/;
$records[-1] .= $_;
  }


Before the loop, how about a subroutine which, given one of the multi-line records,
will return a key value containing the name and serial number. This picks out the
strings and concatenates them with a tab character in between, chosen because it
is unlikely to appear in the data itself.

  sub keyval {
my $rec = shift;
my ($name, $sn);
($name) = $rec =~ m/^displayname:\s+(.+)/m;
($sn) = $rec =~ m/^jdirlastfourssn:\s+(\d+)/m;
join "\t", $name, $sn;
  }


"While there are records left" Here's the loop, including a couple of lines to
remove all non-blank entries from the beginning which will be left by the call
to 'delete' that you see in a moment.

  while (@records) {
until (exists $records[0]) {
  shift @records;
}
:
  }


"Calculate a 'key' from the display name and serial number"

  my $key = keyval($records[0]);

"Find all records in the data with a matching key" This call to 'map'
returns a list of indices of all the records in the array which have
a matching key value. This is bound to include the index zero as the
first record matches itself. If there are more then the length of the
array will be more than 1.

  my $i = 0;
  my @slice = map {
my @i = $i++;
defined $_ and keyval($_) eq $key ? @i : ()
  } @records;


The next two steps together: "If there was only one then print it to
parent file, else print them to file 2. Delete them from the list"
The 'delete' function usefully returns a list of all the records
it deleted, so we can just print the results of deleting the array
slice.

  if (@slice == 1) {
print PARENT delete @[EMAIL PROTECTED];
  }
  else {
print FILE2 delete @[EMAIL PROTECTED];
  }


And you're done. Clearly you need to open filehandles DATA for read
and PARENT and FILE2 for write, but the program's there otherwise.

Let us know if you need help assembling the kit.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help required.....about string/text manipulation

2003-06-14 Thread Chinku Simon
Hi,

I wud like some help in assembling the kit.

Thanks in Advance

--- Rob Dixon <[EMAIL PROTECTED]> wrote:
> Mohit_jain01 wrote:
> >
> > > From: Rob Dixon
> > >
> > > Mohit_jain01 wrote:
> > > >
> > > > I am facing a problem with text file manipulation with Perl.
> > > >
> > > > I have a file with over 2 lac lines of data.
> > > > I need to find the duplicates(strings) in the file and copy those records into 
> > > > another
> file.
> > > >
> > > > Is there a function/module  in Perl by which I can read the duplicates in a 
> > > > file at one go
> and print them
> > > > on to another file.
> > >
> > > Before we can help you we need to know a little more of your problem.
> > >
> > > Are you looking for duplicate lines in the file, or duplicate strings defined
> > > in some other way? How big is the file you want to read (how many lines
> > > or strings do you want to compare)?
> > >
> > > There are modules which will help you write your program, but exactly
> > > how you go about it depends on the details of your problem.
> >
> > I have a big file containing about 20 lines. This file basically contains some 
> > records. A
> sample of the file is as given
> > below:
> >
> > dn: cn=1148734,ou=Employees,dc=jci,dc=com
> >
> > displayname: Herek, Moriah L
> >
> > jdirlastfourssn: 2888
> >
> > dn: cn=1148735,ou=Employees,dc=jci,dc=com
> >
> > displayname: Pelletier, Michael J
> >
> > jdirlastfourssn: 8719
> >
> > uid: cpellem
> >
> [snip data]
> >
> > What I need to do is:
> >
> > 1. Take the first entry and get the value of the display name and jdirlastfourssn 
> > attribute.
> >
> > 2. Check whether there is another record with the same display name attribute 
> > value.
> >(There cud be multiple records)
> >
> >  3. If so then extract both record and write them into another file.
> >
> >  4. Delete these duplicate records from the parent file.
> >
> > 5. Do that for all records.
> >
> 
> I'm not clear whether you mean 200K lines or 200K records (which seem to be mostly
> 6 lines each except for 'Pelletier, Michael J' which has an additional pair of
> lines for a 'uid' value. But, even if it were 200K records at about 100 characters
> each this would be 20Mb, which is well within the capacity of all but the smallest
> computers these days. This problem is far easier with all the data in memory, so
> I'll go that way, and if you find it's not working or is too slow we'll think again.
> 
> OK, so let me rewrite your algorithm a little.
> 
> - Read all records into memory
> - While there are records left
> -   calculate a 'key' from the display name and serial number
> -   find all records in the data with a matching key
> -   if there was only one then print it to parent file, else print them to file 2
> -   delete them from the list
> 
> From the top:
> 
> 
> "Read in all of the records"
> 
> It looks like all the information starts with a line beginning with 'dn:'. If this
> is wrong we'll have to change it.
> 
>   my @records;
> 
>   while () {
> push @records, '' if /^dn:\s+/;
> $records[-1] .= $_;
>   }
> 
> 
> Before the loop, how about a subroutine which, given one of the multi-line records,
> will return a key value containing the name and serial number. This picks out the
> strings and concatenates them with a tab character in between, chosen because it
> is unlikely to appear in the data itself.
> 
>   sub keyval {
> my $rec = shift;
> my ($name, $sn);
> ($name) = $rec =~ m/^displayname:\s+(.+)/m;
> ($sn) = $rec =~ m/^jdirlastfourssn:\s+(\d+)/m;
> join "\t", $name, $sn;
>   }
> 
> 
> "While there are records left" Here's the loop, including a couple of lines to
> remove all non-blank entries from the beginning which will be left by the call
> to 'delete' that you see in a moment.
> 
>   while (@records) {
> until (exists $records[0]) {
>   shift @records;
> }
> :
>   }
> 
> 
> "Calculate a 'key' from the display name and serial number"
> 
>   my $key = keyval($records[0]);
> 
> "Find all records in the data with a matching key" This call to 'map'
> returns a list of indices of all the records in the array which have
> a matching key value. This is bound to include the index zero as the
> first record matches itself. If there are more then the length of the
> array will be more than 1.
> 
>   my $i = 0;
>   my @slice = map {
> my @i = $i++;
> defined $_ and keyval($_) eq $key ? @i : ()
>   } @records;
> 
> 
> The next two steps together: "If there was only one then print it to
> parent file, else print them to file 2. Delete them from the list"
> The 'delete' function usefully returns a list of all the records
> it deleted, so we can just print the results of deleting the array
> slice.
> 
>   if (@slice == 1) {
> print PARENT delete @[EMAIL PROTECTED];
>   }
>   else {
> print FILE2 delete @[EMAIL PROTECTED];
>   }
> 
> 
> And you're done. Clearly you need to open filehandles DATA for read
> and PARENT and FILE2 for write, but 

Re: Help required.....about string/text manipulation

2003-06-15 Thread Rob Dixon
Anybody?

Rob



Chinku Simon wrote:
>
> > Mohit_jain01 wrote:
> > >
> > > > From: Rob Dixon
> > > >
> > > > Mohit_jain01 wrote:
> > > > >
> > > > > I am facing a problem with text file manipulation with Perl.
> > > > >
> > > > > I have a file with over 2 lac lines of data.
> > > > > I need to find the duplicates(strings) in the file and copy those records 
> > > > > into another file.
> > > > >
> > > > > Is there a function/module  in Perl by which I can read the duplicates in a 
> > > > > file at one go and print them
> > > > > on to another file.
> > > >
> > > > Before we can help you we need to know a little more of your problem.
> > > >
> > > > Are you looking for duplicate lines in the file, or duplicate strings defined
> > > > in some other way? How big is the file you want to read (how many lines
> > > > or strings do you want to compare)?
> > > >
> > > > There are modules which will help you write your program, but exactly
> > > > how you go about it depends on the details of your problem.
> > >
> > > I have a big file containing about 20 lines. This file basically contains 
> > > some records. A sample of the file is as given
> > > below:
> > >
> > > dn: cn=1148734,ou=Employees,dc=jci,dc=com
> > >
> > > displayname: Herek, Moriah L
> > >
> > > jdirlastfourssn: 2888
> > >
> > > dn: cn=1148735,ou=Employees,dc=jci,dc=com
> > >
> > > displayname: Pelletier, Michael J
> > >
> > > jdirlastfourssn: 8719
> > >
> > > uid: cpellem
> > >
> > [snip data]
> > >
> > > What I need to do is:
> > >
> > > 1. Take the first entry and get the value of the display name and 
> > > jdirlastfourssn attribute.
> > >
> > > 2. Check whether there is another record with the same display name attribute 
> > > value.
> > >(There cud be multiple records)
> > >
> > >  3. If so then extract both record and write them into another file.
> > >
> > >  4. Delete these duplicate records from the parent file.
> > >
> > > 5. Do that for all records.
> > >
> >
> > I'm not clear whether you mean 200K lines or 200K records (which seem to be mostly
> > 6 lines each except for 'Pelletier, Michael J' which has an additional pair of
> > lines for a 'uid' value. But, even if it were 200K records at about 100 characters
> > each this would be 20Mb, which is well within the capacity of all but the smallest
> > computers these days. This problem is far easier with all the data in memory, so
> > I'll go that way, and if you find it's not working or is too slow we'll think 
> > again.
> >
> > OK, so let me rewrite your algorithm a little.
> >
> > - Read all records into memory
> > - While there are records left
> > -   calculate a 'key' from the display name and serial number
> > -   find all records in the data with a matching key
> > -   if there was only one then print it to parent file, else print them to file 2
> > -   delete them from the list
> >
> > From the top:
> >
> >
> > "Read in all of the records"
> >
> > It looks like all the information starts with a line beginning with 'dn:'. If this
> > is wrong we'll have to change it.
> >
> >   my @records;
> >
> >   while () {
> > push @records, '' if /^dn:\s+/;
> > $records[-1] .= $_;
> >   }
> >
> >
> > Before the loop, how about a subroutine which, given one of the multi-line records,
> > will return a key value containing the name and serial number. This picks out the
> > strings and concatenates them with a tab character in between, chosen because it
> > is unlikely to appear in the data itself.
> >
> >   sub keyval {
> > my $rec = shift;
> > my ($name, $sn);
> > ($name) = $rec =~ m/^displayname:\s+(.+)/m;
> > ($sn) = $rec =~ m/^jdirlastfourssn:\s+(\d+)/m;
> > join "\t", $name, $sn;
> >   }
> >
> >
> > "While there are records left" Here's the loop, including a couple of lines to
> > remove all non-blank entries from the beginning which will be left by the call
> > to 'delete' that you see in a moment.
> >
> >   while (@records) {
> > until (exists $records[0]) {
> >   shift @records;
> > }
> > :
> >   }
> >
> >
> > "Calculate a 'key' from the display name and serial number"
> >
> >   my $key = keyval($records[0]);
> >
> > "Find all records in the data with a matching key" This call to 'map'
> > returns a list of indices of all the records in the array which have
> > a matching key value. This is bound to include the index zero as the
> > first record matches itself. If there are more then the length of the
> > array will be more than 1.
> >
> >   my $i = 0;
> >   my @slice = map {
> > my @i = $i++;
> > defined $_ and keyval($_) eq $key ? @i : ()
> >   } @records;
> >
> >
> > The next two steps together: "If there was only one then print it to
> > parent file, else print them to file 2. Delete them from the list"
> > The 'delete' function usefully returns a list of all the records
> > it deleted, so we can just print the results of deleting the array
> > slice.
> >
> >   if (@slice == 1) {
> > print PARENT delete @[EMAIL P

Re: Help required in writing a script

2008-10-23 Thread Rodrick Brown
Look at Net::SSH.

On Thu, Oct 23, 2008 at 9:36 AM, monnappa appaiah <[EMAIL PROTECTED]>wrote:

> Hi all,
>
> i need  help on something i'm working on.I have 127
> systems connected in the network, i want to write a script which will run
> on
> a management server, i shud be able to connect to each and every system
> (all
> the systems have same password) and execute certain commands and the output
> of those commands shud be put in a filei'm new to perl, can
> somebody
> help me as to how can i do this?
>
> Thanks,
> Monnappa
>



-- 
[ Rodrick R. Brown ]
http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown


Re: Help required in writing a script

2008-10-23 Thread Chas. Owens
On Thu, Oct 23, 2008 at 09:36, monnappa appaiah <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> i need  help on something i'm working on.I have 127
> systems connected in the network, i want to write a script which will run on
> a management server, i shud be able to connect to each and every system (all
> the systems have same password) and execute certain commands and the output
> of those commands shud be put in a filei'm new to perl, can somebody
> help me as to how can i do this?
>
> Thanks,
> Monnappa
>

How do you connect to machines? (ssh, telnet, rlogin,  ouiga board, etc.)
Do you need to collect only stdout or do you need stderr as well?
Does it need to connect to all of the machines in parallel or can it
run serially?

Have you considered existing distributed shells?
http://www.netfort.gr.jp/~dancer/software/dsh.html.en
http://clusterssh.wiki.sourceforge.net/FAQ

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread monnappa appaiah
Hi,
  i connect to machines using ssh, i need to collect only
stdout..connecting to all those machines serially or parllely is fine.

Thanks,
Monnappa



On Thu, Oct 23, 2008 at 7:50 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:

>  On Thu, Oct 23, 2008 at 09:36, monnappa appaiah <[EMAIL PROTECTED]>
> wrote:
> > Hi all,
> >
> > i need  help on something i'm working on.I have 127
> > systems connected in the network, i want to write a script which will run
> on
> > a management server, i shud be able to connect to each and every system
> (all
> > the systems have same password) and execute certain commands and the
> output
> > of those commands shud be put in a filei'm new to perl, can
> somebody
> > help me as to how can i do this?
> >
> > Thanks,
> > Monnappa
> >
>
> How do you connect to machines? (ssh, telnet, rlogin,  ouiga board, etc.)
> Do you need to collect only stdout or do you need stderr as well?
> Does it need to connect to all of the machines in parallel or can it
> run serially?
>
> Have you considered existing distributed shells?
> http://www.netfort.gr.jp/~dancer/software/dsh.html.en
> http://clusterssh.wiki.sourceforge.net/FAQ
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>


Re: Help required in writing a script

2008-10-23 Thread Chas. Owens
On Thu, Oct 23, 2008 at 10:34, monnappa appaiah <[EMAIL PROTECTED]> wrote:
> Hi,
>   i connect to machines using ssh, i need to collect only
> stdout..connecting to all those machines serially or parllely is fine.
>
> Thanks,
> Monnappa
snip

Do you want to run arbitrary commands at any time or specific ones at
specific times.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread monnappa appaiah
i want to run specific commands and the output of those shud be put into a
file.



On Thu, Oct 23, 2008 at 8:13 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:

> On Thu, Oct 23, 2008 at 10:34, monnappa appaiah <[EMAIL PROTECTED]>
> wrote:
> > Hi,
> >   i connect to machines using ssh, i need to collect only
> > stdout..connecting to all those machines serially or parllely is
> fine.
> >
> > Thanks,
> > Monnappa
> snip
>
> Do you want to run arbitrary commands at any time or specific ones at
> specific times.
>
> --
>  Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>


Re: Help required in writing a script

2008-10-23 Thread Philip Durbin

monnappa appaiah wrote:

 i need  help on something i'm working on.I have 127
systems connected in the network, i want to write a script which will run on
a management server, i shud be able to connect to each and every system (all
the systems have same password) and execute certain commands and the output
of those commands shud be put in a filei'm new to perl, can somebody
help me as to how can i do this?


You could use gsh:

gsh myhosts 'my_command.sh' > /tmp/output.txt

http://outflux.net/unix/software/gsh

Phil


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread Chas. Owens
On Thu, Oct 23, 2008 at 10:49, monnappa appaiah <[EMAIL PROTECTED]> wrote:
> i want to run specific commands and the output of those shud be put into a
> file.
snip

So, you will need to learn to use:

Net::SSH (if you want to use keys, this is preferable) -
http://search.cpan.org/dist/Net-SSH/SSH.pm

or

Net::SSH::Expect (if you want to use passwords) -
http://search.cpan.org/dist/Net-SSH-Expect/lib/Net/SSH/Expect.pod

and

IO::File - http://perldoc.perl.org/IO/File.html
fork - http://perldoc.perl.org/functions/fork.html
wait - http://perldoc.perl.org/functions/wait.html
warn - http://perldoc.perl.org/functions/warn.html
die - http://perldoc.perl.org/functions/die.html
exit - http://perldoc.perl.org/functions/exit.html
next - http://perldoc.perl.org/functions/next.html
for(each), while, and until loops and if statements -
http://perldoc.perl.org/perlsyn.html#Compound-Statements

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread monnappa appaiah
Hi,

   i tried to install the "Expect" modulebut i got the below
error msg:

cpan> m /Expect/
Going to read C:\Perl\cpan\Metadata
  Database was generated on Mon, 20 Oct 2008 08:27:31 GMT
ModuleBio::MAGE::QuantitationType::ExpectedValue
(JASONS/Bio-MAGE-20020902.6
.tar.gz)
ModuleCPAN::Test::Dummy::Perl5::Make::Expect
(ANDK/CPAN-Test-Dummy-Perl5-Mak
e-Expect-1.00.tar.gz)
Module  < Expect (RGIERSIG/Expect-1.21.tar.gz)
ModuleExpect::Angel  (MINGZHANG/Angel_002.tar.gz)
ModuleExpect::Simple (DJERIUS/Expect-Simple-0.04.tar.gz)
ModuleIDS::DataSource::HTTP::Expectation (INGHAM/IDS-HTTP-1.01.tar.gz)
ModuleNet::SCP::Expect   (RYBSKEJ/Net-SCP-Expect-0.14.tar.gz)
Module  = Net::SSH::Expect   (BNEGRAO/Net-SSH-Expect-1.09.tar.gz)
ModuleTest::Expect   (LBROCARD/Test-Expect-0.31.tar.gz)
ModuleWWW::Postini::Exception::UnexpectedResponse
(PGUZIS/WWW-Postini-0.01.t
ar.gz)
10 items found


cpan> install Expect
Running install for module 'Expect'
Running make for R/RG/RGIERSIG/Expect-1.21.tar.gz
Fetching with LWP:

http://ppm.activestate.com/CPAN/authors/id/R/RG/RGIERSIG/Expect-1.21.tar.gz
Fetching with LWP:
  http://ppm.activestate.com/CPAN/authors/id/R/RG/RGIERSIG/CHECKSUMS
Checksum for
C:\Perl\cpan\sources\authors\id\R\RG\RGIERSIG\Expect-1.21.tar.gz ok

Scanning cache C:\Perl/cpan/build for sizes
DONE
Expect-1.21/
Expect-1.21/Changes
Expect-1.21/examples/
Expect-1.21/examples/kibitz/
Expect-1.21/examples/kibitz/Changelog
Expect-1.21/examples/kibitz/kibitz
Expect-1.21/examples/kibitz/kibitz.man
Expect-1.21/examples/kibitz/README
Expect-1.21/examples/ssh.pl
Expect-1.21/Expect.pm
Expect-1.21/Expect.pod
Expect-1.21/Makefile.PL
Expect-1.21/MANIFEST
Expect-1.21/META.yml
Expect-1.21/README
Expect-1.21/test.pl
Expect-1.21/tutorial/
Expect-1.21/tutorial/1.A.Intro
Expect-1.21/tutorial/2.A.ftp
Expect-1.21/tutorial/2.B.rlogin
Expect-1.21/tutorial/3.A.debugging
Expect-1.21/tutorial/4.A.top
Expect-1.21/tutorial/5.A.top
Expect-1.21/tutorial/5.B.top
Expect-1.21/tutorial/6.A.smtp-verify
Expect-1.21/tutorial/6.B.modem-init
Expect-1.21/tutorial/README

  CPAN.pm: Going to build R/RG/RGIERSIG/Expect-1.21.tar.gz

Checking if your kit is complete...
Looks good
Warning: prerequisite IO::Pty 1.03 not found.
Warning: prerequisite IO::Tty 1.03 not found.
Writing Makefile for Expect
 Unsatisfied dependencies detected during 
RGIERSIG/Expect-1.21.tar.gz   
IO::Pty [requires]
IO::Tty [requires]
Running make test
  Delayed until after prerequisites
Running make install
  Delayed until after prerequisites
Running install for module 'IO::Pty'
Running make for R/RG/RGIERSIG/IO-Tty-1.07.tar.gz
Fetching with LWP:

http://ppm.activestate.com/CPAN/authors/id/R/RG/RGIERSIG/IO-Tty-1.07.tar.gz
Checksum for
C:\Perl\cpan\sources\authors\id\R\RG\RGIERSIG\IO-Tty-1.07.tar.gz ok

IO-Tty-1.07/
IO-Tty-1.07/ChangeLog
IO-Tty-1.07/Makefile.PL
IO-Tty-1.07/MANIFEST
IO-Tty-1.07/META.yml
IO-Tty-1.07/Pty.pm
IO-Tty-1.07/README
IO-Tty-1.07/test.pl
IO-Tty-1.07/try
IO-Tty-1.07/Tty.pm
IO-Tty-1.07/Tty.xs

  CPAN.pm: Going to build R/RG/RGIERSIG/IO-Tty-1.07.tar.gz

Now let's see what we can find out about your system
(logfiles of failing tests are available in the conf/ dir)...

ERROR: cannot run the configured compiler 'cl'
(see conf/compilerok.log). Suggestions:
1) The complier 'cl' is not in your PATH. Add it
   to the PATH and try again. OR
2) The compiler isn't installed on your system. Install it. OR
3) You only have a different compiler installed (e.g. 'gcc').
   Either fix the compiler config in the perl Config.pm
   or install a perl that was built with the right compiler
   (you could build perl yourself with the available compiler).

Note: this is a system-administration issue, please ask your local
admin for help. Thank you.

Warning: No success on command[C:\Perl\bin\perl.exe Makefile.PL
INSTALLDIRS=site
]
  RGIERSIG/IO-Tty-1.07.tar.gz
  C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site -- NOT OK
Running make test
  Make had some problems, won't test
Running make install
  Make had some problems, won't install
Running install for module 'IO::Tty'
Running make for R/RG/RGIERSIG/IO-Tty-1.07.tar.gz
  Has already been unwrapped into directory
C:\Perl\cpan\build\IO-Tty-1.07-ZOJv0
E
  'C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site' returned status 512,
won't
 make
Running make test
  Make had some problems, won't test
Running make install
  Make had some problems, won't install
Running make for R/RG/RGIERSIG/Expect-1.21.tar.gz
  Has already been unwrapped into directory
C:\Perl\cpan\build\Expect-1.21-9rXmi
o

  CPAN.pm: Going to build R/RG/RGIERSIG/Expect-1.21.tar.gz

Warning: Prerequisite 'IO::Pty => 1.03' for
'R/RG/RGIERSIG/Expect-1.21.tar.gz' f
ailed when processing 'R/RG/RGIERSIG/IO-Tty-1.07.tar.gz' with 'writemakefile
=>
NO 'C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site' returned status 512'.
Con
tinuing, but chances to succeed are limited

Re: Help required in writing a script

2008-10-23 Thread Chas. Owens
On Thu, Oct 23, 2008 at 16:18, monnappa appaiah <[EMAIL PROTECTED]> wrote:
snip
>i tried to install the "Expect" modulebut i got the below
> error msg:
snip
> ERROR: cannot run the configured compiler 'cl'
> (see conf/compilerok.log). Suggestions:
> 1) The complier 'cl' is not in your PATH. Add it
>to the PATH and try again. OR
> 2) The compiler isn't installed on your system. Install it. OR
> 3) You only have a different compiler installed (e.g. 'gcc').
>Either fix the compiler config in the perl Config.pm
>or install a perl that was built with the right compiler
>(you could build perl yourself with the available compiler).
snip

It looks like you do not have the proper C compiler installed (cl is
Microsoft Visual C/C++ if I remember correctly).  You might be helped
by reading this article and its associated links:
http://www.perlmonks.org/?node_id=249803

You might also try Strawberry Perl* instead of ActiveState Perl.

* http://strawberryperl.com/

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread Rob Dixon
monnappa appaiah wrote:
> 
>i tried to install the "Expect" modulebut i got the below
> error msg:

[snip]

> cpan> install Expect
> Running install for module 'Expect'

[snip]

> Checking if your kit is complete...
> Looks good
> Warning: prerequisite IO::Pty 1.03 not found.
> Warning: prerequisite IO::Tty 1.03 not found.

[snip]

> Running make for R/RG/RGIERSIG/IO-Tty-1.07.tar.gz

[snip]

> Now let's see what we can find out about your system
> (logfiles of failing tests are available in the conf/ dir)...
> 
> ERROR: cannot run the configured compiler 'cl'
> (see conf/compilerok.log). Suggestions:
> 1) The complier 'cl' is not in your PATH. Add it
>to the PATH and try again. OR
> 2) The compiler isn't installed on your system. Install it. OR
> 3) You only have a different compiler installed (e.g. 'gcc').
>Either fix the compiler config in the perl Config.pm
>or install a perl that was built with the right compiler
>(you could build perl yourself with the available compiler).
> 
> Note: this is a system-administration issue, please ask your local
> admin for help. Thank you.

[snip]

> can someone help me install this module under windows

In their endless search for money, Microsoft don't supply a C compiler,
assembler, or linker with any version of Windows in the last twenty years or so.
Also, because of several deliberate decisions to make people pay for as much as
possible, it is difficult and awkward to get CPAN working on a Windows platform.

Microsoft's 'nmake' is available for free, but some versions have been more
compatible with standard modules than others, and in any case, as there is still
no C compiler, on its own it is a solution only for pure Perl modules.

Depending on what version of perl you have installed there may be tidier ways of
installing modules on your machine. If you have ActivePerl then ppm is your
answer, but there will still be no 'Expect' module available as it is very tied
to the Unix architecture.

You have reached a dead end I'm afraid, but remember that vanilla Net::SSH
should work fine on your platform.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread Chas. Owens
On Thu, Oct 23, 2008 at 18:07, Rob Dixon <[EMAIL PROTECTED]> wrote:
snip
> In their endless search for money, Microsoft don't supply a C compiler,
> assembler, or linker with any version of Windows in the last twenty years or 
> so.
> Also, because of several deliberate decisions to make people pay for as much 
> as
> possible, it is difficult and awkward to get CPAN working on a Windows 
> platform.
>
> Microsoft's 'nmake' is available for free, but some versions have been more
> compatible with standard modules than others, and in any case, as there is 
> still
> no C compiler, on its own it is a solution only for pure Perl modules.
>
> Depending on what version of perl you have installed there may be tidier ways 
> of
> installing modules on your machine. If you have ActivePerl then ppm is your
> answer, but there will still be no 'Expect' module available as it is very 
> tied
> to the Unix architecture.
>
> You have reached a dead end I'm afraid, but remember that vanilla Net::SSH
> should work fine on your platform.
snip

You can actually get the Visual C/C++ compiler for free from Microsoft
(see the link in my last email).  The general answer, though, seems to
be to use Strawberry Perl instead of ActiveState Perl.  Strawberry
Perl comes with its own compiler and version of make.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-23 Thread Rob Dixon
Chas. Owens wrote:
> On Thu, Oct 23, 2008 at 18:07, Rob Dixon <[EMAIL PROTECTED]> wrote:
>>
>> Microsoft's 'nmake' is available for free, but some versions have been more
>> compatible with standard modules than others, and in any case, as there is 
>> still
>> no C compiler, on its own it is a solution only for pure Perl modules.
> 
> You can actually get the Visual C/C++ compiler for free from Microsoft
> (see the link in my last email).  The general answer, though, seems to
> be to use Strawberry Perl instead of ActiveState Perl.  Strawberry
> Perl comes with its own compiler and version of make.

Microsoft have always struggled with offering things for free, and there have
been many handicapped versions of MS Visual C++ available in the last few years.
Unless I have missed something, the PerlMonks entry that you linked ends up at
http://msdn.microsoft.com/visualc/vctoolkit2003/ that is now a dead link. There
is probably a similar current download, but I have given up chasing MS policy.

I have paid less attention than I should to Strawberry Perl and what it will do,
and the home page looks very promising. But I have to say that 'Expect' works at
a  very low level, and simple provision of a C compiler will not make the ends
meet. A huge amount of work went into making 'threads' a cross-platform pragma,
and while I hope Strawberry Perl has done something miraculous I will want to
see it for myself.

For all Windows' complexity and awkwardness, it is worth remembering that it has
relatively few variants compared to Unix. The same applies to Mac OS, OS/2, VMS
and so on. That means that while any of these platforms have fewer modules
available to them, anything that is distributed prebuilt has a high likelihood
of working out of the box. Compromises are wonderful things.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Help required in writing a script

2008-10-28 Thread Philip Durbin

On Oct 23, 2008, at 11:22 AM, Philip Durbin wrote:


monnappa appaiah wrote:
i need  help on something i'm working on.I have  
127
systems connected in the network, i want to write a script which  
will run on
a management server, i shud be able to connect to each and every  
system (all
the systems have same password) and execute certain commands and  
the output
of those commands shud be put in a filei'm new to perl, can  
somebody

help me as to how can i do this?


You could use gsh:

gsh myhosts 'my_command.sh' > /tmp/output.txt

http://outflux.net/unix/software/gsh

Phil


Here's an example of using gsh:

http://stackoverflow.com/questions/243750/how-can-i-automate-running-commands-remotely-over-ssh#245114

Phil

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: "Help Required" might not get you help

2003-11-14 Thread Rob Dixon
Rob Richardson wrote:
>
> A general thought:  Subject lines should tell people what the subject
> of the e-mail is.  On many lists and newsgroups dedicated to
> programming languages, many of the most knowledgeable people won't
> bother reading messages with vague subjects like "Help Required".  They
> don't want to waste their time on things they might not be able to help
> with.  You will get much better results with subjects like "How can I
> use CGI to go to a URL?"

Although in practise you'll probably rally support if you
post something like:

  From:Rapunzel
  Subject: Help! I'm stuck at the top of this tower!

Sad, isn't it :)

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: "Help Required" might not get you help

2003-11-14 Thread Charles K. Clarkson
Rob Richardson <[EMAIL PROTECTED]> wrote:
: 
: A general thought:  Subject lines should tell people what the
: subject of the e-mail is.  On many lists and newsgroups
: dedicated to programming languages, many of the most
: knowledgeable people won't bother reading messages with vague
: subjects like "Help Required".  They don't want to waste their
: time on things they might not be able to help with.  You will
: get much better results with subjects like "How can I use CGI
: to go to a URL?"

I don't frequent the USENET much any more, but I used to
filter certain questions out by using the subject. As I recall
I marked posts as read that had the words "newbie" or "new to
perl" and "urgent" in them. Being new to perl did not mean you
had to be new to USENET. And it didn't mean you had to ignore
the common courtesies that had been established.

At first I thought it a bit unfair to arbitrarily mark a
post (or a poster) because they had obviously never read the
etiquette rules for USENET. But the shear volume of messages
requires at least some filtering. My first attempts marked
areas I did not possess an interest. Even then, I would often
read posts from people who either disregarded netiquette or
had never read them.

After a few months I started blocking senders. I like to
share my knowledge with others, but I appreciate those who
take the time to properly ask questions. There are a lot of
people who post correctly. Why bother with the people who
can't be bothered to use good subjects, use sentence case,
capitalize "i" or spell out words like "are"? (And started
blocking anyone who top-posted.)

Here I am taking the time to reply, double check my
sources, test any code I include, and proof-read my message
and I need to continually click on the ignore button of my
spell-checker as it catches errors in the quoted text.

I tend to be more lenient here on these lists, but I
monitor three perl beginner lists and they are all dumped
into one folder. Some days are busy and I'll look at
messages with descriptive subjects first. Sometimes I
don't get to the non-descriptive subjects.

Some days I feel like starting a message board for
people who like to help on message boards. Then I could
post quotes from particularly annoying posts in the "Look
what the Idiots Posted Today" forum.  :)




Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328





















-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help required to extract multiple text fields from a textstring

2012-05-27 Thread Dr.Ruud

On 2012-05-26 14:51, pa...@fsmail.net wrote:


split is slower than the correct regex matching.




--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




What is Variable Interpolation [was: Re: Help Required on the Script]

2006-04-06 Thread D. Bolliger
Mazhar am Donnerstag, 6. April 2006 11.48:
> thanks Raymond for the help it works,
> and what do u mean by variable interpolation

Hello Mazhar

It will help you a lot to know and use the documentation system of perl. 
You can get an overview by typing (on the command line):

perldoc perl
(docs)

perldoc perldoc 
(documentation system)

For your question with interpolatation, see

perldoc perlop
(and there "Quote and Quote-like Operators" and 
"Regexp Quote-Like Operators")

For builtin funtions (here, the example is "q"):

perldoc -f q

Some questions are answered by

perldoc -q your question or some word(s) of the question

The online docs can be found at http://www.perl.org/docs.html

Variable interpolation is expanding variable values into a string, done by 
double quotes (or qq). Think about the following code (run in from command 
line):

perl -le '
  use strict; use warnings;
  my $word=q{Tip: };
  my @words=qw/ look at the docs /;
  print q($word @words), "\n";
  print qq($word @words\n);
'

btw, @04 is not a valid (array) variable name; they must not start with a 
digit, as not keyword/builtin does.

Other tips: When asking questions,
- choose an apropriate subject line
- snip away irrelevant parts of the post


HTH!

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Help required to extract multiple text fields from a text string

2012-05-25 Thread pangj

May you try this matching?

while() {
next unless /^(\S+\s+)(\S+\s+)(\S+\s+).*\"(.*?)\"/;
print "$1 $2 $3 $4\n";
}

HTH.


 Message Received: May 25 2012, 09:52 PM
 From: "Christopher Gray" 
 To: beginners@perl.org
 Cc: 
 Subject: Help required to extract multiple text fields from a text string
 
 Good day,
 
 I have a text file containing records.  While I can extract single
 sub-strings, I cannot extract multiple sub-strings.
 
 The records are of multiple types - only about a third of which have the
 data I need.
 
 An example of a "good" record is
 
  Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
 
 I'm trying to extract the first (Abc1234), second (open), third (A basket of
 melons) and fourth (1) strings.
 
 I can extract each of them separately - but not together.
 
 So - for example:
 
   while () {
   chomp;
 next if !/\{\s+fruittype\s+(\d+)\s+}/;
 my $Temp =$1;
   }
 
 Extracts the fruittype.  However, when I try and have multiple extracts:
 
   ...
next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
   ...
 It fails.
 
 What have I done wrong?
 
 Chris
 
 
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 
 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-25 Thread timothy adigun
Hi Chris,

On Fri, May 25, 2012 at 11:53 PM,  wrote:

>
> May you try this matching?
>
> while() {
>next unless /^(\S+\s+)(\S+\s+)(\S+\s+).*\"(.*?)\"/;
>print "$1 $2 $3 $4\n";
> }
>
> HTH.
>
> 
>  Message Received: May 25 2012, 09:52 PM
>  From: "Christopher Gray" 
>  To: beginners@perl.org
>  Cc:
>  Subject: Help required to extract multiple text fields from a text string
>
>  Good day,
>
>  I have a text file containing records.  While I can extract single
>  sub-strings, I cannot extract multiple sub-strings.
>
>  The records are of multiple types - only about a third of which have the
>  data I need.
>
>  An example of a "good" record is
>
>  Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
>
>  I'm trying to extract the first (Abc1234), second (open), third (A basket
> of
>  melons) and fourth (1) strings.
>
>  I can extract each of them separately - but not together.
>
>  So - for example:
>
>   while () {
>   chomp;
> next if !/\{\s+fruittype\s+(\d+)\s+}/;
> my $Temp =$1;
>   }
>
>  Extracts the fruittype.  However, when I try and have multiple extracts:
>
>   ...
>next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
>   ...
>  It fails.
>
>  What have I done wrong?
>
>  Chris
>
>
 You didn't show the type of record that is incorrect, however, from your
code, I suppose a corrcet record would contain fruittype.

In the single match, your regex matches, but doesn't when trying to match
several.

while() {
   next unless
m/(.+?)\s+?.+?\s.+?(.+?)\s+?.+?\"(.+?)\".+?\{\s+fruittype\s+(.+?)\}/;
   print "$1 $2 $3 $4\n"; # print Abc1234  open A basket of melons 1
}

-- tim


RE: Help required to extract multiple text fields from a text string

2012-05-26 Thread Christopher Gray
Hi,

Thank you for looking to help me.  Unfortunately, when I used your code nothing 
was extracted.  At least when I printed $1 nothing appeared.

In order to help me learn more about Perl - I'd like to know why my code didn't 
work.  If I understand your code correctly then I should see:

$1 = Abc123, $2 = STATUS, $3 = open, $3 = DESCRIPTION, etc.

While anything would be better than my puny effort, I was looking just to 
extract the "data" - in other words:

   $1 = "Abc123", $2 = "open", $3 = "a basket of melons", $4 = "1".

I thought I was successfully copying from a similar script - but obviously I 
don't have enough understanding in order to make it work. If I take my code 
apart, I thought that:

\STATUS\s+(\w+)\s+   would extract the word between STATUS and 
DESCRIPTION, and
\{\s+fruittype\s+(\d+)\s+}   would extract the number following 
"fruittype"

Individually they do - it is just when I add then together in the same line 
that I receive nothing.  What am I doing wrong?

Chris

-Original Message-
From: pa...@fsmail.net [mailto:pa...@fsmail.net] 
Sent: 25 May 2012 11:53 PM
To: Christopher Gray; beginners@perl.org
Subject: RE: Help required to extract multiple text fields from a text string


May you try this matching?

while() {
next unless /^(\S+\s+)(\S+\s+)(\S+\s+).*\"(.*?)\"/;
print "$1 $2 $3 $4\n";
}

HTH.


 Message Received: May 25 2012, 09:52 PM
 From: "Christopher Gray" 
 To: beginners@perl.org
 Cc: 
 Subject: Help required to extract multiple text fields from a text string
 
 Good day,
 
 I have a text file containing records.  While I can extract single  
sub-strings, I cannot extract multiple sub-strings.
 
 The records are of multiple types - only about a third of which have the  data 
I need.
 
 An example of a "good" record is
 
  Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
 
 I'm trying to extract the first (Abc1234), second (open), third (A basket of
 melons) and fourth (1) strings.
 
 I can extract each of them separately - but not together.
 
 So - for example:
 
   while () {
   chomp;
 next if !/\{\s+fruittype\s+(\d+)\s+}/;
 my $Temp =$1;
   }
 
 Extracts the fruittype.  However, when I try and have multiple extracts:
 
   ...
next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
   ...
 It fails.
 
 What have I done wrong?
 
 Chris
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org  For additional 
commands, e-mail: beginners-h...@perl.org  http://learn.perl.org/
 
 
 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, 
e-mail: beginners-h...@perl.org http://learn.perl.org/





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread timothy adigun
Hi Chris,

On Sat, May 26, 2012 at 8:14 AM, Christopher Gray <
christopher.g...@talktalk.net> wrote:

> Hi,
>
> Thank you for looking to help me.  Unfortunately, when I used your code
> nothing was extracted.  At least when I printed $1 nothing appeared.
>
> In order to help me learn more about Perl - I'd like to know why my code
> didn't work.  If I understand your code correctly then I should see:
>
>$1 = Abc123, $2 = STATUS, $3 = open, $3 = DESCRIPTION, etc.
>
> While anything would be better than my puny effort, I was looking just to
> extract the "data" - in other words:
>
>   $1 = "Abc123", $2 = "open", $3 = "a basket of melons", $4 = "1".
>
> I thought I was successfully copying from a similar script - but obviously
> I don't have enough understanding in order to make it work. If I take my
> code apart, I thought that:
>
>\STATUS\s+(\w+)\s+   would extract the word between STATUS and
> DESCRIPTION, and
>\{\s+fruittype\s+(\d+)\s+}   would extract the number following
> "fruittype"
>
> Individually they do - it is just when I add then together in the same
> line that I receive nothing.  What am I doing wrong?
>
> Chris
>
> -
>
   You gave this as a type of good record:

 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}

 Let me include the line below as a type of incorrect record,
 That is if "fruittype" is common to all correct record:

 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { 1}

 Case1: say we are to match to get Abc 1234, one can do this:

   while(){
  next unless m/(.+?)\s+?.+?\{\s+?fruittype.+?\}$/;
 print $1,$/ # prints Abc1234 for the first line
   }

__DATA__
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { 1}

Case 2: say again we want to match 'A basket of melons', at a different
times we can do this:

   while(){
  next unless m/.+?\"(.+?)\".+?\{\s+?fruittype.+?\}$/;
 print $1,$/ # prints A basket of melons
   }

__DATA__
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { 1}

Let say we want to output both 'Abc1234' and 'A basket of melons', then we
need to merge the two regex togther like so:
 ..
  next unless m/(.+?)\s+?.+?\"(.+?)\".+?\{\s+?fruittype.+?\}$/;
   print "$1 $2",$/ # prints Abc1234 A basket of melons
 .

We can't use either of those previous regex, it won't match.
In that light to get what you wanted i.e
$1 = "Abc123", $2 = "open", $3 = "a basket of melons", $4 = "1".

use this:

while() {
   next unless
m/(.+?)\s+?.+?\s.+?(.+?)\s+?.+?\"(.+?)\".+?\{\s+fruittype\s+(.+?)\}/;
   print "$1 $2 $3 $4\n"; # prints Abc1234  open A basket of melons 1
}

__DATA__
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}
 Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { 1}

Pls Note that the second record will not match atall because it doesn't
have fruittype.
Copy the code in the cases out and test them, yourself it works.
Hope this helps


Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Dr.Ruud

On 2012-05-25 22:51, Christopher Gray wrote:


I have a text file containing records.  While I can extract single
sub-strings, I cannot extract multiple sub-strings.


Try split, see perldoc -f split.

while ( my $line= <$fh_in> ) {

my @data= split ' ', $line;

;
}

--
Ruud


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread pangj
split is slower than the correct regex matching.



 Message Received: May 26 2012, 10:59 AM
 From: "Dr.Ruud" 
 To: beginners@perl.org
 Cc: 
 Subject: Re: Help required to extract multiple text fields from a text string
 
 On 2012-05-25 22:51, Christopher Gray wrote:
 
 > I have a text file containing records.  While I can extract single
 > sub-strings, I cannot extract multiple sub-strings.
 
 Try split, see perldoc -f split.
 
  while ( my $line= <$fh_in> ) {
 
  my @data= split ' ', $line;
 
  ;
  }
 
 -- 
 Ruud
 
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 
 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Rob Dixon

On 26/05/2012 13:51, pa...@fsmail.net wrote:


split is slower than the correct regex matching.


That is complete nonsense. Can you show a benchmark that supports your
claim?

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread pangj
There are many cases prove that, I am just lazy to find one.
You don't know it, so it's nonsense?



 Message Received: May 26 2012, 01:58 PM
 From: "Rob Dixon" 
 To: beginners@perl.org
 Cc: pa...@fsmail.net
 Subject: Re: Help required to extract multiple text fields from a text string
 
 On 26/05/2012 13:51, pa...@fsmail.net wrote:
 >
 > split is slower than the correct regex matching.
 
 That is complete nonsense. Can you show a benchmark that supports your
 claim?
 
 Rob
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 
 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Rob Dixon

On 25/05/2012 21:51, Christopher Gray wrote:

Good day,

I have a text file containing records.  While I can extract single
sub-strings, I cannot extract multiple sub-strings.

The records are of multiple types - only about a third of which have the
data I need.

An example of a "good" record is

  Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}

I'm trying to extract the first (Abc1234), second (open), third (A basket of
melons) and fourth (1) strings.

I can extract each of them separately - but not together.

So - for example:

   while () {
   chomp;
 next if !/\{\s+fruittype\s+(\d+)\s+}/;
 my $Temp =$1;
   }

Extracts the fruittype.  However, when I try and have multiple extracts:

   ...
next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
   ...
It fails.

What have I done wrong?


Hi Chris

Lets look at your regex

  /\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/

First of all you start with a \S, which will actually match any 
non-space character, not the S that you intended. But that wouldn't 
break your regex.


The regex as a whole is looking for

  'STATUS'
  some whitespace
  some 'word' characters (0..9, A..Z, a..z and _)
  some whitespace
  an open brace '{'
  some whitespace
  'fruittype'
  some whitespace
  some digits (0..9)
  some whitespace
  a closing brace (which should reall be escaped but Perl forgives you)

This will match a string like

  '---XTATUS  www  {  fruittype  999  }'

But since "STATUS open " is followed by "DESCRIPTION" in your record
instead of an opening brace the match fails.

To match multiple fields, you can write a regex that matches the entire
string with parentheses around the parts that must be captured. This
will do what you want

  while () {
my @data = 
/(\w+)\s+STATUS\s+(\w+)\s+DESCRIPTION\s+"([^"]+)"\s+::\s+\{\s*fruittype\s+(\d+)\s*\}/;

print "$_\n" for @data;
  }

**output**

  Abc1234
  open
  A basket of melons
  1

but you may need to adjust the regex if the quoted string can be
unquoted if is doesn't contain spaces.

HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Jim Gibson

On May 26, 2012, at 5:51 AM, pa...@fsmail.net wrote:

> split is slower than the correct regex matching.
> 

Did you know that split uses a regular expression to find the separators on 
which to split the string? So your claim is unlikely to be true. In any case, 
the difference between using split and a single regular expression is likely to 
be insignificant. You shouldn't worry about such trivial differences. Chris 
just wants to extract some data from a file, and it won't matter to him if it 
takes a few extra nanoseconds.

The best advice when worrying about efficiency is this: first get the program 
working correctly. Then, if it is too slow, find out where the bottlenecks are 
and try to optimize those. Usually, the most gains can be achieved by changing 
the algorithm, not the implementation. 
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Rob Dixon

On 26/05/2012 14:07, pa...@fsmail.net wrote:

From: "Rob Dixon"

On 26/05/2012 13:51, pa...@fsmail.net wrote:


 split is slower than the correct regex matching.


That is complete nonsense. Can you show a benchmark that supports your
claim?


There are many cases prove that, I am just lazy to find one.
You don't know it, so it's nonsense?


I do know, and it is nonsense.

The benchmark below shows that split is better than twice as fast as a
regex for the application I have chosen.

If you can rewrite the program to show a diffferent use of regexes where
they are faster than an equivalent split then I will take it back.

Please stop deliberately spreading misinformation.

Rob


use strict;
use warnings;

use Benchmark 'cmpthese';
use List::Util 'shuffle';

my $str;

for my $i (1 .. 101) {
  if ($i & 1) {
$str .= join '', (shuffle 'A' .. 'Z')[0..rand 10];
  }
  else {
$str .= ' ' x (rand 10 + 1);
  }
}

cmpthese(-5, {
  split => sub {
my @array = split ' ', $str;
  },
  regex => sub {
my @array = $str =~ /\S+/g;
  },
})

__END__

**OUTPUT**

 Rate regex split
regex 16744/s--  -55%
split 37360/s  123%--

Tool completed successfully

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Help required to extract multiple text fields from a text string

2012-05-26 Thread Christopher Gray
Brilliant - a first class "teach-in".  Many thanks for the description - it
all works.  Brilliant.


-Original Message-
From: Rob Dixon [mailto:rob.di...@gmx.com] 
Sent: 26 May 2012 2:13 PM
To: beginners@perl.org
Cc: Christopher Gray
Subject: Re: Help required to extract multiple text fields from a text
string

On 25/05/2012 21:51, Christopher Gray wrote:
> Good day,
>
> I have a text file containing records.  While I can extract single 
> sub-strings, I cannot extract multiple sub-strings.
>
> The records are of multiple types - only about a third of which have 
> the data I need.
>
> An example of a "good" record is
>
>   Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype
1}
>
> I'm trying to extract the first (Abc1234), second (open), third (A 
> basket of
> melons) and fourth (1) strings.
>
> I can extract each of them separately - but not together.
>
> So - for example:
>
>while () {
>chomp;
>  next if !/\{\s+fruittype\s+(\d+)\s+}/;
>  my $Temp =$1;
>}
>
> Extracts the fruittype.  However, when I try and have multiple extracts:
>
>...
> next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
>...
> It fails.
>
> What have I done wrong?

Hi Chris

Lets look at your regex

   /\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/

First of all you start with a \S, which will actually match any non-space
character, not the S that you intended. But that wouldn't break your regex.

The regex as a whole is looking for

   'STATUS'
   some whitespace
   some 'word' characters (0..9, A..Z, a..z and _)
   some whitespace
   an open brace '{'
   some whitespace
   'fruittype'
   some whitespace
   some digits (0..9)
   some whitespace
   a closing brace (which should reall be escaped but Perl forgives you)

This will match a string like

   '---XTATUS  www  {  fruittype  999  }'

But since "STATUS open " is followed by "DESCRIPTION" in your record instead
of an opening brace the match fails.

To match multiple fields, you can write a regex that matches the entire
string with parentheses around the parts that must be captured. This will do
what you want

   while () {
 my @data =
/(\w+)\s+STATUS\s+(\w+)\s+DESCRIPTION\s+"([^"]+)"\s+::\s+\{\s*fruittype\s+(\
d+)\s*\}/;
 print "$_\n" for @data;
   }

**output**

   Abc1234
   open
   A basket of melons
   1

but you may need to adjust the regex if the quoted string can be unquoted if
is doesn't contain spaces.

HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional
commands, e-mail: beginners-h...@perl.org http://learn.perl.org/





-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Chris Charley

""Christopher Gray""  wrote in message news

Good day,

I have a text file containing records.  While I can extract single
sub-strings, I cannot extract multiple sub-strings.

The records are of multiple types - only about a third of which have the
data I need.

An example of a "good" record is

Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}

I'm trying to extract the first (Abc1234), second (open), third (A basket 
of

melons) and fourth (1) strings.

I can extract each of them separately - but not together.

So - for example:

 while () {
 chomp;
   next if !/\{\s+fruittype\s+(\d+)\s+}/;
   my $Temp =$1;
 }

Extracts the fruittype.  However, when I try and have multiple extracts:

 ...
  next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
 ...
It fails.

What have I done wrong?

Chris


Hello Chris

Just to show another way to do it, using Text::ParseWords which has been
part of the core since perl 5. (To use only if file format is consistent.)

#!/usr/bin/perl
use strict;
use warnings;
use Text::ParseWords;

my @data;

while () {
   chomp;

   # use substitution operator to remove the end of the line
   next unless s/\s*::\s*\{\s*fruittype\s*(\d+).+//;
   my $fruittype = $1;

   push @data, { 'id', quotewords('\s+', 0, $_), type => $fruittype };
}

use Data::Dumper; print Dumper \@data;

__DATA__
Abc1234 STATUS   open  DESCRIPTION "A basket of melons" :: { fruittype 1}


*** Dumper prints
$VAR1 = [
 {
   'DESCRIPTION' => 'A basket of melons',
   'STATUS' => 'open',
   'type' => '1',
   'id' => 'Abc1234'
 }
   ];


Hope this helps,
Chris 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Adams Paul

Sent from my LG phone

Jim Gibson  wrote:

>
>On May 26, 2012, at 5:51 AM, pa...@fsmail.net wrote:
>
>> split is slower than the correct regex matching.
>> 
>
>Did you know that split uses a regular expression to find the separators on 
>which to split the string? So your claim is unlikely to be true. In any case, 
>the difference between using split and a single regular expression is likely 
>to be insignificant. You shouldn't worry about such trivial differences. Chris 
>just wants to extract some data from a file, and it won't matter to him if it 
>takes a few extra nanoseconds.
>
>The best advice when worrying about efficiency is this: first get the program 
>working correctly. Then, if it is too slow, find out where the bottlenecks are 
>and try to optimize those. Usually, the most gains can be achieved by changing 
>the algorithm, not the implementation. 
>--
>To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>For additional commands, e-mail: beginners-h...@perl.org
>http://learn.perl.org/
>
>
>


Re: Help required to extract multiple text fields from a text string

2012-05-26 Thread Shlomi Fish
Hi Paul,

On Sat, 26 May 2012 20:26:14 -0700
Adams Paul  wrote:

> 
> Sent from my LG phone
> 

Why have you already sent 4 messages to this mailing list, which contain nothing
except this "Sent from my LG phone" notice and the entire replied-to message
quoted below (with only a plain text part)? Is this due to a usability problem
with your smartphone? Can you prevent this from happening again?

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Better be a tail for the lions, than the head of the jackals.
— Pirkei Avot, 4 15

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread Shawn H Corey

On 12-05-27 02:00 AM, Shlomi Fish wrote:

On Sat, 26 May 2012 20:26:14 -0700
Adams Paul  wrote:


>
>  Sent from my LG phone
>

Why have you already sent 4 messages to this mailing list, which contain nothing
except this "Sent from my LG phone" notice and the entire replied-to message
quoted below (with only a plain text part)? Is this due to a usability problem
with your smartphone? Can you prevent this from happening again?


It is likely a butt dial. It will stop when he calls someone else and 
their number in then on redial.



--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

_Perl links_
official site   : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help: http://perlmonks.org/
documentation   : http://perldoc.perl.org/
news: http://perlsphere.net/
repository  : http://www.cpan.org/
blog: http://blogs.perl.org/
regional groups : http://www.pm.org/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread Michael Rasmussen
On Sat, May 26, 2012 at 05:52:19PM +0100, Rob Dixon wrote:
> On 26/05/2012 14:07, pa...@fsmail.net wrote:
>> From: "Rob Dixon"
>>> On 26/05/2012 13:51, pa...@fsmail.net wrote:

  split is slower than the correct regex matching.
>>>
>>> That is complete nonsense. Can you show a benchmark that supports your
>>> claim?
> I do know, and it is nonsense.
>
> The benchmark below shows that split is better than twice as fast as a
> regex for the application I have chosen.
>
> If you can rewrite the program to show a diffferent use of regexes where
> they are faster than an equivalent split then I will take it back.
>
> Please stop deliberately spreading misinformation.
> cmpthese(-5, {
>   split => sub {
> my @array = split ' ', $str;
>   },
>   regex => sub {
> my @array = $str =~ /\S+/g;
>   },
> })

Curious, splitting on single char - what split has been optimized for, the awk 
behavior,
but the regex comparsion is splitting on non-whitespace, the inverse of what 
split is doing.  
Correcting \S to \s returns similar results. 

But that raises the question of what happens when not splitting on the highly 
optimized space scenario.
First, let's see what happens when both split and the regex act on \S:
cmpthese(-5, {
  split => sub {
my @array = split /\S+/, $str;
  },
  regex => sub {
my @array = $str =~ /\S+/g;
  },
})
 Rate regex split
regex 44162/s--   -1%
split 44501/s1%--

Now, what happens if our whitespace is mixed between tabs and spaces:
 Rate regex split
regex 40420/s--  -34%
split 61438/s   52%--

How about the not uncommon case of simple CSV?

#  $str .= ' ' x (rand 10 + 1);
$str .= ",";
# change the /\S+/ to /,/

 Rate regex split
regex 63021/s--   -8%
split 68790/s9%--


Perhaps the lesson is split on whitespace else regex


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
There are those who listen and those who wait to talk.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread John W. Krahn

Michael Rasmussen wrote:

On Sat, May 26, 2012 at 05:52:19PM +0100, Rob Dixon wrote:

On 26/05/2012 14:07, pa...@fsmail.net wrote:

From: "Rob Dixon"

On 26/05/2012 13:51, pa...@fsmail.net wrote:


  split is slower than the correct regex matching.


That is complete nonsense. Can you show a benchmark that supports your
claim?

I do know, and it is nonsense.

The benchmark below shows that split is better than twice as fast as a
regex for the application I have chosen.

If you can rewrite the program to show a diffferent use of regexes where
they are faster than an equivalent split then I will take it back.

Please stop deliberately spreading misinformation.
cmpthese(-5, {
   split =>  sub {
 my @array = split ' ', $str;
   },
   regex =>  sub {
 my @array = $str =~ /\S+/g;
   },
})


Curious, splitting on single char - what split has been optimized for, the awk 
behavior,
but the regex comparsion is splitting on non-whitespace,


The regular expression is not splitting!  It is capturing.

split removes whitespace.

The regular expression captures non-whitespace.

So the two expressions posted above are equivalent.



the inverse of what split is doing.
Correcting \S to \s returns similar results.


Did you actually examine the results produced?



But that raises the question of what happens when not splitting on the highly 
optimized space scenario.
First, let's see what happens when both split and the regex act on \S:
cmpthese(-5, {
   split =>  sub {
 my @array = split /\S+/, $str;


Remove non-whitespace and return whitespace.



   },
   regex =>  sub {
 my @array = $str =~ /\S+/g;


Capture and return non-whitespace.



   },
})




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread Michael Rasmussen
On Sun, May 27, 2012 at 07:24:26PM -0700, John W. Krahn wrote:
> Michael Rasmussen wrote:
>> [ a bunch of blather, snipped here ]
>
> The regular expression is not splitting!  It is capturing.
> split removes whitespace.
> The regular expression captures non-whitespace.
> So the two expressions posted above are equivalent.

 


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Follow the carrot.
~ http://someoneoncetoldme.com/gallery/14052010

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What is Variable Interpolation [was: Re: Help Required on the Script]

2006-04-06 Thread John W. Krahn
D. Bolliger wrote:
> 
> btw, @04 is not a valid (array) variable name; they must not start with a 
> digit, as not keyword/builtin does.

$ perl -Mwarnings -Mstrict -le' our @04 = 10 .. 14; print "@04"'
10 11 12 13 14

You are probably thinking scalars and/or lexicals.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: What is Variable Interpolation [was: Re: Help Required on the Script]

2006-04-07 Thread D. Bolliger
John W. Krahn am Freitag, 7. April 2006 01.09:
> D. Bolliger wrote:
> > btw, @04 is not a valid (array) variable name; they must not start with a
> > digit, as not keyword/builtin does.
>
> $ perl -Mwarnings -Mstrict -le' our @04 = 10 .. 14; print "@04"'
> 10 11 12 13 14
>
> You are probably thinking scalars and/or lexicals.

John, 
yes I did:

$ perl -Mwarnings -Mstrict -le' my @04 = 10 .. 14; print "@04"'
Can't use global @04 in "my" at -e line 1, near "my @04 "
[...]

Now I get the idea of the hint in the error I was (for a too short time) 
wondering about!

Thanks!

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]