[24632] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6796 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 12:14:14 2004

Date: Tue, 3 Aug 2004 09:10:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 3 Aug 2004     Volume: 10 Number: 6796

Today's topics:
          http://www.bisexualplayground.com/welcome.php?r=jon_m <Me@here.org>
        'pattern match read eof' error, what does it mean? (ZoloftGuy)
    Re: 'pattern match read eof' error, what does it mean? <Joe.Smith@inwap.com>
    Re: 'pattern match read eof' error, what does it mean? (ZoloftGuy)
        .perldb interface to DDD (Roman Kaganovich)
        .perldb interface to DDD <nospam@nospam.com>
        2 methods to get the domains's IP,but neither of them i <eloelono1@sina.com>
    Re: 2 methods to get the domains's IP,but neither of th <nobull@mail.com>
    Re: 2 methods to get the domains's IP,but neither of th <artgh@hotmail.com>
        [ANNOUNCE] CGI::Builder::SessionManager 1.00 <enrico@sorcinelli.it>
        [networking] Convert subnet mask <=> mask length <bigal187.invalid@adexec.com>
    Re: [networking] Convert subnet mask <=> mask length <jgibson@mail.arc.nasa.gov>
    Re: [networking] Convert subnet mask <=> mask length <jliebgott@member.fsf.org>
    Re: [networking] Convert subnet mask <=> mask length <wblock@wonkity.com>
    Re: [networking] Convert subnet mask <=> mask length <bart.lateur@pandora.be>
    Re: `our' declaration causing problems with `strict' pr <nobull@mail.com>
    Re: Accessing form POST data <sbryce@scottbryce.com>
    Re: Accessing form POST data <tadmc@augustmail.com>
        add a "suffix" to a variable in a array (Laura)
        add a "suffix" to a variable in a array (Laura)
    Re: add a "suffix" to a variable in a array <gogala@sbcglobal.net>
    Re: add a "suffix" to a variable in a array <t_lawetta@yahoo.com>
    Re: add a "suffix" to a variable in a array <bowsayge@nomail.afraid.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 28 Jul 2004 18:38:48 GMT
From: "Me" <Me@here.org>
Subject:   http://www.bisexualplayground.com/welcome.php?r=jon_mary420
Message-Id: <YoSNc.56665$fv.20017@fe2.columbus.rr.com>




  http://www.bisexualplayground.com/welcome.php?r=jon_mary420


    Copy and paste to browser
    
    Cum join us







------------------------------

Date: 31 Jul 2004 11:31:12 -0700
From: zoloftguy@myrealbox.com (ZoloftGuy)
Subject: 'pattern match read eof' error, what does it mean?
Message-Id: <d4376e99.0407311031.6e26cae4@posting.google.com>

The goal is to reboot and/or shutdown a Nortel Contivity box with PERL
and the Telnet Script. Here is the script:

use Net::Telnet ();

###Prompt is "$"

$t = new Net::Telnet (Timeout => 30, Prompt => '/[\$]/');
$t->input_log('input.txt');
$t->output_log('output.txt');
$t->open("nortelcontivity");
$t->waitfor('/Login:/');
$t->print("admin");
$t->waitfor('/Password:/');
$t->print("thepassword");
$t->waitfor('/CES\>/');
$t->print("en");
$t->waitfor('/Password:/');
$t->print("thepassword");
$t->print("reload restart");
@output1 = $t->cmd('y');
print @output1;
$t->close;

It works, the box reboots, but I get this error:

pattern match read eof at C:\temp\yo.pl line 18

Can anyone tell me what this error means? Please feel free to optimize
the script. I'm hacking away at this script without knowing much about
what I am doing.

Thanks


------------------------------

Date: Sun, 01 Aug 2004 06:44:39 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: 'pattern match read eof' error, what does it mean?
Message-Id: <rj0Pc.225110$XM6.194098@attbi_s53>

ZoloftGuy wrote:

> The goal is to reboot and/or shutdown a Nortel Contivity box with PERL
> and the Telnet Script. Here is the script:
> 
> use Net::Telnet ();
> 
> ###Prompt is "$"
> 
> $t = new Net::Telnet (Timeout => 30, Prompt => '/[\$]/');
> $t->input_log('input.txt');
> $t->output_log('output.txt');
> $t->open("nortelcontivity");
> $t->waitfor('/Login:/');
> $t->print("admin");
> $t->waitfor('/Password:/');
> $t->print("thepassword");
> $t->waitfor('/CES\>/');
> $t->print("en");
> $t->waitfor('/Password:/');
> $t->print("thepassword");
> $t->print("reload restart");
> @output1 = $t->cmd('y');
> print @output1;
> $t->close;
> 
> It works, the box reboots, but I get this error:
> 
> pattern match read eof at C:\temp\yo.pl line 18

I am able to reproduce the error report on Linux using a fake `en`.
Here's what it looks like when using $t->input_log('-'); $t->output_log('-');

linux% perl yo.pl
Red Hat Linux release 9 (Shrike)
login: admin
admin
Password: thepassword

Last login: Sat Jul 31 23:08:00 from localhost
CES>en
en
Password: thepassword
reload restart
y
thepassword
reload restart
y
Password accepted
command is reload restart (y/n)
bin/en: faking a reset by killing parent pid 11655
[1] 11688
logout
pattern match read eof at yo.pl line 18
linux%

> Can anyone tell me what this error means?

Since you did not provide a prompt for $t->cmc('y'), Net::Telnet was using
the Prompt set in the initial connection, '$'.  After sending the 'y', it
was waiting for a dollar sign, but instead got an eof because the server
closed the telnet connection during its reset.

If you don't want to see that message, change $t->errmode() just before cmd().

$t->errmode(sub {die @_ unless $_[0] =~ /eof/});  # Be quiet about getting eof
@output1 = $t->cmd('y');			  # 'reset' causes telnet eof

	-Joe



------------------------------

Date: 2 Aug 2004 10:30:30 -0700
From: zoloftguy@myrealbox.com (ZoloftGuy)
Subject: Re: 'pattern match read eof' error, what does it mean?
Message-Id: <d4376e99.0408020930.6139f9e6@posting.google.com>

This worked. Thank you Joe Smith, 

You will be honored to know that I credited you in the script:

# Thanks Joe Smith at comp.lang.perl.misc

I would make the screen print something before launch but I haven't
figured out how to do that yet.

Thanks much.


------------------------------

Date: 26 Jul 2004 23:52:37 -0700
From: rkaganov@ort.org.il (Roman Kaganovich)
Subject: .perldb interface to DDD
Message-Id: <a3cd74f7.0407262252.43a6a73c@posting.google.com>

Hello ,

How can I define initial command for DDD when debugging perl script,
like aliases for graph display or list of variables etc.
What a .perldb format for this.

The perldebug manual cover only .gdbinit part of interface to DDD. 

Thanks


------------------------------

Date: Wed, 28 Jul 2004 13:16:00 +0300
From: Roman Kaganovich <nospam@nospam.com>
Subject: .perldb interface to DDD
Message-Id: <41077CE0.4010509@nospam.com>

Hello ,

How can I define initial command for DDD when debugging perl script,
like aliases for graph display or list of variables etc.
What a .perldb format for this.

The perldebug manual cover only .gdbinit part of interface to DDD.

Thanks



------------------------------

Date: Sun, 01 Aug 2004 12:56:08 +0800
From: eloelo <eloelono1@sina.com>
Subject: 2 methods to get the domains's IP,but neither of them is good.
Message-Id: <2n3bgtFsg4d2U1@uni-berlin.de>

I have lots of domains' name(nearly 1000) in a text file which called 
"domain.txt".It looks like this:

domain.txt
www.yahoo.com
www.msn.com
www.aol.com
 ...

Now,I want to get their IP addresses(include all IPs. e.g,yahoo has many 
IP,I want to get them all),and put the results into a new text file called 
"IPlist.txt".It looks like this:

IPlist.txt
www.yahoo.com,66.94.230.51
www.yahoo.com,66.94.230.52
www.yahoo.com,66.94.230.43
 ...
www.msn.com,202.108.250.249
www.msn.com,61.135.152.77
www.msn.com,61.135.150.75
 ...


I have two methods to achive my goal above but neither is good.

Method#1
It can only get one IP of each domain.In most cases it's not a 
problem.But,when a domain has more than one IP,like yahoo,it can get only 
one IP.And it costs lots of time before it gets the result.

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

my $domain_file  = 'domain.txt';
my $IPlist_file = 'IPlist.txt';

open my $domain,  '<', $domain_file  or die "Cannot open $domain_file: $!";
open my $IPlist, '>', $IPlist_file or die "Cannot open $IPlist_file: $!";

while ( <$domain> ) {
     chomp;
         my $ip = gethostbyname $_;
         print $IPlist "$_,",",",inet_ntoa( $ip ), "\n" if defined $ip;
     }

Method#2
It can get all of the IP of some domain which has more than one IP,but at 
the same time I can also get lots of query failed domain.

#!/usr/local/bin/perl
use Net::DNS;

open(D1,"domain.txt");
@line=<D1>;
$num=@line;
close(D1);
open(D2,">IPlist.txt");
open(FP,">fail");
for($i=0;$i<$num;$i++)
{
  
  chop($line[$i]);
  my $timeout = 15;
  my $res   = Net::DNS::Resolver->new;
  my $query = $res->search($line[$i]);
  
  if ($query) {
      foreach my $rr ($query->answer) {
          next unless $rr->type eq "A";
          print D2 $line[$i],',',$rr->address,"\n";
      }
  } else {
      print FP $line[$i], "query failed: ", $res->errorstring, "\n";
  }
}


Anyone has a better way to solve this problem?Thanks in advance.








------------------------------

Date: 01 Aug 2004 12:49:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: 2 methods to get the domains's IP,but neither of them is good.
Message-Id: <u9vfg3m637.fsf@wcl-l.bham.ac.uk>

eloelo <eloelono1@sina.com> writes:

> It can only get one IP of each domain.

>          my $ip = gethostbyname $_;

Are you under the mistaken impression that gethostbyname will only
return one IP address?

perldoc -f gethostbyname

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Mon, 02 Aug 2004 11:36:52 +0800
From: Facco Eloelo <artgh@hotmail.com>
Subject: Re: 2 methods to get the domains's IP,but neither of them is good.
Message-Id: <410fb6b3.12288800@news.individual.net>

This is what I did:

#!/usr/bin/perl
use Socket;
use Net::hostent;

my $domain_file  = 'D1.txt';
my $IPlist_file = 'D2.txt';

open my $domain,  '<', $domain_file  or die "Cannot open $domain_file: $!";
open my $IPlist, '>', $IPlist_file or die "Cannot open $IPlist_file: $!";

while ( <$domain> ) 
{
	chomp;
	$name = $_;
	
	if ($hent = gethostbyname($name)) 
	{
		$addr_ref  = $hent->addr_list;
		@addresses = map { inet_ntoa($_) } @$addr_ref;
	}
	
	$num=@addresses;
	for ($i=0;$i<$num;$i++) 
	{
	print $IPlist "$name,$addresses[$i]\n";
	}
}
--
>eloelo <eloelono1@sina.com> writes:
>
>> It can only get one IP of each domain.
>
>>          my $ip = gethostbyname $_;
>
>Are you under the mistaken impression that gethostbyname will only
>return one IP address?
>
>perldoc -f gethostbyname



------------------------------

Date: Thu, 29 Jul 2004 15:37:59 GMT
From: Enrico Sorcinelli <enrico@sorcinelli.it>
Subject: [ANNOUNCE] CGI::Builder::SessionManager 1.00
Message-Id: <I1qH8x.1qAI@zorch.sf-bay.org>

The uploaded file

    CGI-Builder-SessionManager-1.00.tar.gz

has entered CPAN as

  file: $CPAN/authors/id/E/EN/ENRYS/CGI-Builder-SessionManager-1.00.tar.gz
  size: 3459 bytes
   md5: 4c26c6d56afa06ff53bfc464d2cd6d26

I've included perldoc at the bottom of this mail.

Any comment and/or criticism are welcome :-)

by

	- Enrico

---


NAME
    CGI::Builder::SessionManager - CGI::Builder / Apache::SessionManager
    integration

SYNOPSIS
       package WebApp;
       use CGI::Builder qw/ CGI::Builder::SessionManager /;

       sub PH_session {
          my $cbf = shift;
          $cbf->page_content = 'Session test page!';
          $cbf->sm->{'foo'} = 'baz';
          $cbf->page_content .= $cbf->sm->{'foo'};
       }

DESCRIPTION
    CGI::Builder::SessionManager is a CGI::Builder extension that integrates
    Apache::SessionManager session management into CGI::Builder framework
    (CBF).

    Apache::SessionManager is a mod_perl (1.0 and 2.0) module that helps
    session management of a web application. This module is a wrapper around
    Apache::Session persistence framework for session data. It creates a
    session object and makes it available to all other handlers
    transparenlty. See 'perldoc Apache::SessionManager' for module
    documentation and use.

INSTALLATION
    In order to install and use this package you will need Perl version
    5.005 or better.

    Prerequisites:

    * CGI::Builder >= 1.2
    * Apache::SessionManager >= 1.01

    Installation as usual:

       % perl Makefile.PL
       % make
       % make test
       % su
         Password: *******
       % make install

PROPERTIES
    This module adds "sm" property to the standard CBF properties.

    It's possible to set a value in current session with:

       $cbf->sm->{'foo'} = 'baz';

    and it's possible to read value session with:

       print $cbf->sm->{'foo'};   

METHODS
  sm_destroy
    Destroy the current session object.

       $cbf->sm_destroy;

EXAMPLES
    This is a simple CGI::Builder application, (save it, for example, as
    /some/path/cgi-builder/WebApp.pm):

       package WebApp;    # your class name
       use CGI::Builder qw/ CGI::Builder::SessionManager /;
       use Data::Dumper;
  
       sub PH_AUTOLOAD {                           # always called for all requested pages
          my $cbf = shift;
          $cbf->page_content = "Default content";  # defines the page content
       }

       sub PH_session {
          my $cbf = shift;
          $cbf->page_content = "Session test!<BR>\n";
          $cbf->sm->{"$$-" . rand()} = rand;
          $cbf->page_content .= '<PRE>' . Dumper($s->cbf) . '</PRE>';
            }

       sub PH_delete_session {
          my $cbf = shift;
          $cbf->page_content = "Session test! (deletion)";
          $cbf->sm_destroy;
       }

    and the correspondent configuration lines in httpd.conf:

       <IfModule mod_perl.c>

          PerlModule Apache::SessionManager
          PerlTransHandler Apache::SessionManager

          Alias /cgi-builder "/usr/local/apache/cgi-builder"
          <Location /cgi-builder>
             SetHandler perl-script
             PerlHandler Apache::Registry
             PerlSendHeader On
             PerlSetupEnv   On
             Options +ExecCGI

             PerlSetVar SessionManagerTracking On
             PerlSetVar SessionManagerExpire 1800
             PerlSetVar SessionManagerInactivity 900
             PerlSetVar SessionManagerName CBFSESSIONID
             PerlSetVar SessionManagerStore File
             PerlSetVar SessionManagerStoreArgs "Directory => /tmp/apache_session_data/cbf"
             PerlSetVar SessionManagerDebug 1
          </Location>   

       </IfModule>

    In order to test this simple application you must implement the Instance
    Script that is what is actually called by your web server.

    It is a very small, simple file which simply creates an instance of your
    application and calls an inherited method, "process()". Following is the
    entirely of /some/path/cgi-builder/webapp.cgi:

       #!/usr/local/bin/perl -w
       use WebApp;
       my $webapp = new WebApp;
       $webapp->process();

    Restart the httpd server and launch
    *http://localhost/cgi-builder/webapp.cgi* .

BUGS
    Please submit bugs to CPAN RT system at
    http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Builder-SessionManager
    or by email at bug-cgi-builder-sessionmanager@rt.cpan.org

    Patches are welcome and I'll update the module if any problems will be
    found.

VERSION
    Version 1.00

SEE ALSO
    Apache::SessionManager, CGI::Builder

AUTHOR
    Enrico Sorcinelli, <enrico at sorcinelli.it>

COPYRIGHT AND LICENSE
    Copyright (C) 2004 by Enrico Sorcinelli

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.8.2 or, at
    your option, any later version of Perl 5 you may have available.




------------------------------

Date: Wed, 28 Jul 2004 16:18:43 -0700
From: "187" <bigal187.invalid@adexec.com>
Subject: [networking] Convert subnet mask <=> mask length
Message-Id: <2mqqikFp4f4aU1@uni-berlin.de>

For example, how can I go from 255.255.252.0 to /22 (as in, for example,
150.10.10.10/22) and vice versa.

I've bane up and down both www.google.com and groups.google.com, tried
searching by perl group, and even globally, and nothing, just online
calculators. Calculators are nice tools, but I really want to know *how*
it's done :)

Thanks.




------------------------------

Date: Wed, 28 Jul 2004 17:33:48 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: [networking] Convert subnet mask <=> mask length
Message-Id: <280720041733483774%jgibson@mail.arc.nasa.gov>

In article <2mqqikFp4f4aU1@uni-berlin.de>, 187
<bigal187.invalid@adexec.com> wrote:

> For example, how can I go from 255.255.252.0 to /22 (as in, for example,
> 150.10.10.10/22) and vice versa.
> 
> I've bane up and down both www.google.com and groups.google.com, tried
> searching by perl group, and even globally, and nothing, just online
> calculators. Calculators are nice tools, but I really want to know *how*
> it's done :)

Well here is one way:

#!/usr/local/bin/perl
use strict;
my $adr = '255.255.252.0';
my $naddr = unpack 'N', (pack 'CCCC', (split( /\./, $adr)));
my $len = 0;
while( $naddr ) {
  $len++;
  $naddr <<= 1;
}
print "length of mask is $len\n";


------------------------------

Date: Wed, 28 Jul 2004 18:35:20 -0700
From: "Jim Liebgott" <jliebgott@member.fsf.org>
Subject: Re: [networking] Convert subnet mask <=> mask length
Message-Id: <opsbvlc6f3xszi1g@hecate.lan>

On Wed, 28 Jul 2004 16:18:43 -0700, 187 <bigal187.invalid@adexec.com>  
wrote:


$subnet='255.255.252.0';
@octets=split(/\./,$subnet);
$bits=40;
do
{
   $last_octet=pop(@octets);
   $bits-=8;
}
while (!$last_octet && @octets);
if (@octets)
{
   while (!($last_octet%2))
   {
     $bits--;
     $last_octet>>=1;
   }
}
print $bits,"\n";


> For example, how can I go from 255.255.252.0 to /22 (as in, for example,
> 150.10.10.10/22) and vice versa.
>
> I've bane up and down both www.google.com and groups.google.com, tried
> searching by perl group, and even globally, and nothing, just online
> calculators. Calculators are nice tools, but I really want to know *how*
> it's done :)
>
> Thanks.
>
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


------------------------------

Date: Thu, 29 Jul 2004 01:50:57 -0000
From: Warren Block <wblock@wonkity.com>
Subject: Re: [networking] Convert subnet mask <=> mask length
Message-Id: <slrncggm01.t3f.wblock@speedy.wonkity.com>

187 <bigal187.invalid@adexec.com> wrote:
> For example, how can I go from 255.255.252.0 to /22 (as in, for example,
> 150.10.10.10/22) and vice versa.
>
> I've bane up and down both www.google.com and groups.google.com, tried
> searching by perl group, and even globally, and nothing, just online
> calculators. Calculators are nice tools, but I really want to know *how*
> it's done :)

A couple of other examples have been shown that count bits; here's an 
alternate:

#!/usr/bin/perl

use warnings;
use strict;

use Socket;

print '/', unpack('%32b*', inet_aton($ARGV[0])), "\n";

-- 
Warren Block * Rapid City, South Dakota * USA


------------------------------

Date: Thu, 29 Jul 2004 10:31:07 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: [networking] Convert subnet mask <=> mask length
Message-Id: <4tjhg01tf3r2a60lgoc1j5orm2ome1ano1@4ax.com>

Warren Block wrote:

>use Socket;
>
>print '/', unpack('%32b*', inet_aton($ARGV[0])), "\n";

That's just beautiful.

It does depend on the fact that you assume the input will match the
binary pattern /^1*0*$/, and you can't be sure...

My version makes sure it does. It also follows a more conventional
route.

	#!/usr/local/bin/perl -wl
	use Socket;

	my $ip = '255.255.252.0';

	if(unpack('B*', inet_aton($ip)) =~ /^(1*)0*$/) {
	    print "/" . length $1;
	} else {
	    print "No match";
	}

-- 
	Bart.


------------------------------

Date: 23 Jul 2004 20:29:26 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: `our' declaration causing problems with `strict' pragma across files
Message-Id: <u9oem6frop.fsf@wcl-l.bham.ac.uk>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> Peter Scott <Peter@PSDT.com> wrote in comp.lang.perl.misc:
> > In article <cdlpnn$qi2$1@mamenchi.zrz.TU-Berlin.DE>,
> >  anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> > >Dave Bakhash <cadet@alum.mit.edu> wrote in comp.lang.perl.misc:
> > >> BEGIN { require "/path/to/Foo.pm"; }
> > >
> > >"BEGIN { require ... } is nearly equivalent to "use".
> > 
> > Except that use won't accept a string like that, the argument has to be a
> > bareword...
> 
> True.  I should have known that trying to gloss over that wouldn't work :)

Usually one would do something like:

use lib '/path/to';
use Foo;

Or

BEGIN { require '/path/to/Foo.pl' }

It is IMNSO confusing to use .pm suffix (usually associated with Perl5
modules) for something that's loaded like a Perl4-style library.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Sat, 24 Jul 2004 16:11:32 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Accessing form POST data
Message-Id: <10g5nkghun59089@corp.supernews.com>

Mark wrote:
> I'm not a Perl expert yet (mainly PHP) but as I need to use a little bit of
> Perl for a website so I basically copied this code available on several web
> tutorials (so I am guessing it is the standard way of doing it).

No, it isn't.

<code snipped>

> BTW, I've also been warned <snip> to use CGI.pm.

That would be the standard way to do it.

cpan.org is your friend.

http://cpan.uwinnipeg.ca/htdocs/CGI.pm/CGI.html



------------------------------

Date: Sat, 24 Jul 2004 17:57:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Accessing form POST data
Message-Id: <slrncg5qbf.7tf.tadmc@magna.augustmail.com>

Mark <noonehere@fakoaddresso.como> wrote:

> I am having
> trouble accessing the POST variables that are posted to my page from another
> form on a different server.


   perldoc -q CGI

       How do I decode a CGI form?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 26 Jul 2004 17:52:27 -0700
From: handl@mts.net (Laura)
Subject: add a "suffix" to a variable in a array
Message-Id: <e0ddcf8.0407261652.5a4d2b0e@posting.google.com>

I dont know if I can explain this correctly by here goes.
I am trying to write a perl program that takes a file let say it looks
like this...
xxxx001,00 0 05 21,TELN NOT 
xxxx002,00 0 01 30,TELN NOT 
xxxx008,00 0 04 15,TELN NOT 
xxxx013,00 0 02 30,CUST HAS 
xxxx015,00 0 10 22,CUST HAS

I want to also insert a few things to this file...
I want to prompt user to enter in
print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
print "Enter ROOM:"; $ROOM=<STDIN> ; chomp $ROOM;

Also I want a areacode fixed to the first column so when all is said
and done, I have part of the script but can not add the areacode to
it???

#!/opt/perl/bin/perl
$acode="204";
print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
print "Enter ROOM:"; $room=<STDIN> ; chomp $room;
while(<ARGV>) {
chomp;
@a=split(",",$_);
print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;

How do I add 204 at the beginning of the [1]?

204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT


------------------------------

Date: 26 Jul 2004 17:52:31 -0700
From: handl@mts.net (Laura)
Subject: add a "suffix" to a variable in a array
Message-Id: <e0ddcf8.0407261652.d523415@posting.google.com>

I dont know if I can explain this correctly by here goes.
I am trying to write a perl program that takes a file let say it looks
like this...
xxxx001,00 0 05 21,TELN NOT 
xxxx002,00 0 01 30,TELN NOT 
xxxx008,00 0 04 15,TELN NOT 
xxxx013,00 0 02 30,CUST HAS 
xxxx015,00 0 10 22,CUST HAS

I want to also insert a few things to this file...
I want to prompt user to enter in
print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
print "Enter ROOM:"; $ROOM=<STDIN> ; chomp $ROOM;

Also I want a areacode fixed to the first column so when all is said
and done, I have part of the script but can not add the areacode to
it???

#!/opt/perl/bin/perl
$acode="204";
print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
print "Enter ROOM:"; $room=<STDIN> ; chomp $room;
while(<ARGV>) {
chomp;
@a=split(",",$_);
print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;

How do I add 204 at the beginning of the [1]?

204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT


------------------------------

Date: Mon, 26 Jul 2004 22:16:08 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: add a "suffix" to a variable in a array
Message-Id: <pan.2004.07.27.02.16.07.374652@sbcglobal.net>

On Mon, 26 Jul 2004 17:52:31 -0700, Laura wrote:

> I dont know if I can explain this correctly by here goes.
> I am trying to write a perl program that takes a file let say it looks

> @a=split(",",$_);
> print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;
> 
> How do I add 204 at the beginning of the [1]?
> 
> 204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT

You have 2 choices:

1) @a=("203",@a);
2) $a[0] .= "203";

It works for the whole tri-state area: 202 (NJ), 212, 718, 516 (NYC) and
203 (CT). 

-- 
A city is a large community where people are lonesome together.



------------------------------

Date: Tue, 27 Jul 2004 14:21:10 +0200
From: Tony Muler <t_lawetta@yahoo.com>
Subject: Re: add a "suffix" to a variable in a array
Message-Id: <410648b9@news.vo.lu>

Mladen Gogala wrote:

> You have 2 choices:

There is more than 2 ways to do it ;-)

> 1) @a=("203",@a);
> 2) $a[0] .= "203";

3) unshift @a, '203';

However, I tried it with @a having 3 to 20 elements, and
in either case it doesn't matter in terms of performance.

T.






------------------------------

Date: Tue, 27 Jul 2004 13:33:24 GMT
From: bowsayge <bowsayge@nomail.afraid.org>
Subject: Re: add a "suffix" to a variable in a array
Message-Id: <EQsNc.15892$f4.7674@newsread3.news.atl.earthlink.net>

Laura said to us:

[...]
> How do I add 204 at the beginning of the [1]?
> 
> 204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT

@a = ($acode, $a[0], $bld, $room, @a[1..$#a] )
print "@a\n";

-- 
bowsayge
bow-say-ge?



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6796
***************************************


home help back first fref pref prev next nref lref last post