Re: how to replace multiple whit space with ", ".

2005-08-30 Thread Jeff Pan


s/\s+/, /g;

On Wed, 31 Aug 2005 01:40:38 +0200, "Bernard van de Koppel"
<[EMAIL PROTECTED]> said:
> Hi,
> 
> How can I replace multiple white space with ", " (comma space).
> 
> "thisis a space"
> 
> should be changed to 
> "this, is a, space"
> 
> Hope someone can help,
> 
> Bernard
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
  unladen european swallow


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




Socket Problem

2005-08-31 Thread Jeff Pan
HI,

I have a pair of C/S socket scripts running for a long time,without any
problem.There is just one server,and more than 120 clients,which all run
on linux box.
This day,beacuse of our network blocking,which mean many lost
packages,my server script became incorrect.It fork more than 1000 child
processes which can't exit.I think the reason is that the server can't
receive the EOF signal,which sent by client via shutdown(1) call,because
of the network blocking. But how can I resolve this problem?

this is client's socket code:

my $sock=IO::Socket::INET->new(PeerAddr => SERVER,
   PeerPort => PORT,
   Proto=> 'tcp');
print $sock $var,CRLF;
$sock->shutdown(1);


and this is server's socket code:

my $listen_socket = IO::Socket::INET->new( 
   LocalAddr => IPADDR,
   LocalPort => PORT,
   Listen=> 150,
   Proto => 'tcp',
   Reuse => 1,
   Timeout   => 3600,
 );
die "can't create socket: $@" unless defined $listen_socket;

while(1)
{
next unless my $connection = $listen_socket->accept;
die "can't fork:$!" unless defined (my $child = fork());

if ($child==0)
{
$listen_socket->close;
&writelog($connection);
exit 0;
}

$connection->close;
}


thanks.
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - A fast, anti-spam email service.


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




Re: parsing long strings

2005-09-02 Thread Jeff Pan

$strings='toDNExtension:, toDNFailure:,';

foreach (split/,\s*/,$strings)
{
$hash{(split/:/,$_)[0]} = (split/:/,$_)[1];
}


is this useful?

On Fri,  2 Sep 2005 09:41:54 -0400 (EDT), "Tom Allison"
<[EMAIL PROTECTED]> said:
> 
> I have a really long string that looks like
> 'toDNExtension:, toDNFailure:, '
> 
> and I want to parse it into key/value pairs...
> 
> I tried:
> 
> foreach ( $string =~ /([\w\s]+):([\w\s]+)/g ) {
> ...
> }
> 
> But I always get only the last pair...  I thought the /g would stop that
> behaviour..
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
  unladen european swallow


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




Re: Could u plz tell me how to remove white spacees present between delimiter

2005-09-02 Thread Jeff Pan


$_='abc, def,  xyz, mno';
s/,\s+/,/g;

On Fri, 2 Sep 2005 20:53:52 +0530, [EMAIL PROTECTED] said:
> 
> Hi Perlers
> 
> 
> I have a file like this in which data is 
> abc,def,xyz,mno, 
> 
> means the delimter is comma here
> 
> but in the string if it comes abc, def,  xyz, mno
> 
> then plz tell me how to remove this white space.
> 
> 
> Mayank Ahuja
> Assistant System Engineer
> Tata Consultancy Services Limited
> Ph:- 044-5816
> Cell:- 9283199460
> Mailto: [EMAIL PROTECTED]
> Website: http://www.tcs.com
> 
> Notice: The information contained in this e-mail message and/or
> attachments to it may contain confidential or privileged information.  
> If you are not the intended recipient, any dissemination, use, review,
> distribution, printing or copying of the information contained in this
> e-mail message and/or attachments to it are strictly prohibited.   If you
> have received this communication in error, please notify us by reply
> e-mail or telephone and immediately and permanently delete the message
> and any attachments.  Thank you
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?


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




Re: mysql server has gone away

2005-09-04 Thread Jeff Pan


try this:
$sql_user = "username";
$sql_pass = "password";
$host = '127.0.0.1';
$sql_conn = "dbi:mysql:dbname:$host:3306";

On Sun, 4 Sep 2005 13:09:29 +0100, "dan" <[EMAIL PROTECTED]> said:
> hey
> i have a problem that's now really really frustrating me. it's probably
> not
> a problem with the perl program itself, but it's the only thing that's
> actually given me this error, and i was wondering if anyone's ever come
> across this before.
> i've just upgraded from mysql 3.23.55 to 3.23.59. now, no matter what i
> try,
> every time i launch my perl program, i get this:
> 
> [EMAIL PROTECTED] ~/cucco]$ DBD::mysql::st execute failed: MySQL server has
> gone
> away at ./bot.pl line 117,  line 69.
> DBD::mysql::st execute failed: MySQL server has gone away at ./bot.pl
> line
> 117,  line 75.
> 
> i've tried moving code around various places, and the error appears on
> every
> $sth->execute i try to run. i connect to the db using:
> 
> $sql_user = "username";
> $sql_pass = "password";
> $sql_conn = "dbi:mysql:dbname:localhost:3306";
> $dbh = DBI->connect($sql_conn, $sql_user, $sql_pass) or die "Can't
> connect
> to SQL Server: $DBI::errstr\n";
> 
> then all the sql statements are run by doing:
> $sth = $dbh->prepare("SQL STATEMENT");
> $sth->execute;
> and it's the above execute line it says the mysql server's gone away on.
> the
> other thing is, it goes away instantly. the wait_timeout on the sql
> server's
> still default (8 hours, i believe). and i've *never* had a problem with
> this
> code before. something's happened to a configuration, or something, and i
> can't figure out why. i'm now tearing my hair out over this.
> has anyone ever come across this before? if so, how did you fix it?
> 
> many thanks
> dan
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Send your email first class


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




Re: naming subroutine reference parameter?

2005-09-06 Thread Jeff Pan

On Tue, 6 Sep 2005 16:12:35 +0800, "Jayvee Vibar" <[EMAIL PROTECTED]>
said:
> How do you name subroutine reference parameter in perl?
> Naming a local or pass by value is by simply using my ($param1, $param2)
> =
> @_ ;
> How about by reference? I think it would be harder if I'll be using
> $_[0],
> $_[1] direct method.
> Is it possible?
> 
> Thanks.
> 


Passing reference as parameter to subroutine is as easy as the normal
way.And,if u pass some types of parameter such as hash,array,or handle
to subroutine,using reference instead is more safer.
for example,such below code is right:

my (%hash,@array);
&sub_test(\%hash,[EMAIL PROTECTED]);

sub sub_test{
my ($hash_ref,$array_ref)[EMAIL PROTECTED];
my %hash=%$hash_ref;
my @[EMAIL PROTECTED];
do something...
}
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - IMAP accessible web-mail


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




Re: naming subroutine reference parameter?

2005-09-06 Thread Jeff Pan

> > my (%hash,@array);
> > &sub_test(\%hash,[EMAIL PROTECTED]);
> 
> & has special meaning so it should be dropped when not needing
> particular special behavior.

I can't understand for this,can u give me some examples?


> > my %hash=%$hash_ref;
> > my @[EMAIL PROTECTED];
> 
> This isn't needed actually and it only makes unnecessary overhead as
> keys/values are copied, so you immediately lost benefit by passing by
> reference.
> 
> It's better to access them directly like,
> $hash_ref->{key}
> $array_ref->[0]
> 
> > do something...
> > }

This point is great,thank u.
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?


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




Re: deciphering regular expressions

2005-09-07 Thread Jeff Pan
find this:
/data/Shows*"

such as:
/data/Shows"
/data/Shows.jpg"
/data/Shows888"
/data/Shows/other"
...

the double quote has no special meaning.



On Wed, 7 Sep 2005 00:36:08 -0700 (PDT), "Christopher Spears"
<[EMAIL PROTECTED]> said:
> I am trying to figure out what the following regular
> expression is look for:
> 
> if ( $line =~ /(\/data\/Shows.*)"/ )
> 
> Is it trying to find a line that has the phrase
> dataShows in it?  What is the double quote for?
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Or how I learned to stop worrying and
  love email again


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




Re: Looping over an array of hashes problem

2005-09-08 Thread Jeff Pan

maybe u would try:

foreach my $key (keys %{$AoH[$map_loop{$i}]}) {
...
}

because $AoH[$map_loop{$i}] is just a ref,so u get wrong.

On Thu, 08 Sep 2005 09:42:33 +0100, "Graeme McLaren"
<[EMAIL PROTECTED]> said:
> Morning all, I have a problem that I can't see a way around.  Basically I 
> have an array of hashes and I want to get the key and value of each hash
> but 
> with the following code I'm getting:
> 
> Type of arg 1 to keys must be hash (not array element) at 
> /usr/lib/perl5/vendor_perl/Purchaser/Common.pm line 477, near "]) "
> 
> #code:
> 
> foreach my $key (keys $AoH[$map_loop{$i}]) {
>  my $value = $AoH[$map_loop{$i}]->{$key};
> 
>   }
> 
> 
> Is there a way to loop over an array of hashes?
> 
> 
> Cheers for any light you can shed on this?
> 
> 
> Cheers,
> 
> Graeme :)
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - mmm... Fastmail...


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




Re: extract web pages from a web site

2005-09-08 Thread Jeff Pan
LWP::Simple can do that.

On Thu, 8 Sep 2005 14:45:26 +0100, "José Pedro Silva Pinto"
<[EMAIL PROTECTED]> said:
> Hi there,
> 
>  
> 
> I am doing a program in perl to extract some web pages (And copy it to a
> local file), from a given web address.
> 
>  
> 
> Which perl module can I use to help me to do this task
> 
>  
> 
> Thanks
> 
>  
> 
>  
> 
> José Pinto
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - mmm... Fastmail...


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




Re: 2-way lookup

2005-09-08 Thread Jeff Pan
#/usr/bin/perl
my $i=0;
my %hash;

while (<>)
{
chomp;
s/^\s+|\s+$//g;
$hash{$i}=[split];
$i++;
}

print $hash{0}->[0],"\n";
print $hash{1}->[2],"\n";

Is this useful?




On Fri, 9 Sep 2005 12:11:33 +1000 , "Keenan, Greg John (Greg)** CTR **"
<[EMAIL PROTECTED]> said:
> Hi,
>  
> I have a file like:
>  
>   A   B   C
> 1aa11bb11cc11
> 2aa22bb22cc22
> 3aa33bb33cc33
> 4aa44bb44cc44
>  
> I have two sets of coordinates like (A2, C1) and I need to join them
> together like aa22cc11
>  
> I am going to pull the relevent line for the first coordinate into an
> array
> then pull out the relevant element then repeat the steps for the second
> coordinate e.g.
>  
> @lines = ;
> @line = $lines[3];
> $coordData1 = $line[1];
> @line = $lines[2];
> $coordData2 = $line[3];
> ...do something with $coordData1 & $coordData2
>  
> I'm hoping for a better way and I'm looking for suggestions.
>  
> Thanks for your time.
> 
> Greg Keenan 
> Lucent Technologies * 
> Level 1, 68 Waterloo Road 
> North Ryde NSW 2113 
> Australia 
> * +61 2 9491 6898 
> * [EMAIL PROTECTED] 
> 
>  
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - The way an email service should be


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




Re: 2-way lookup

2005-09-08 Thread Jeff Pan
Sure,this code is more brief:

$hash{$i++}=[split] while (<>);

thank u.


On Thu, 08 Sep 2005 19:54:11 -0700, "John W. Krahn" <[EMAIL PROTECTED]>
said:
> Jeff Pan wrote:
> > #/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> > my $i=0;
> > my %hash;
> > 
> > while (<>)
> > {
> > chomp;
> > s/^\s+|\s+$//g;
> > $hash{$i}=[split];
> > $i++;
> 
> You could write those four lines as:
> 
> $hash{$i++}=[split];
> 
> 
> > }
> > 
> > print $hash{0}->[0],"\n";
> > print $hash{1}->[2],"\n";
> > 
> > Is this useful?
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Send your email first class


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




Re: catching output from ping

2005-09-09 Thread Jeff Pan
if (`ping $blade` =~ /$badPing/) {print "$blade:
$badPing\n";}

change to:

my @results=`ping -c1 $blade`;
print "$blade:$badPing\n" if grep /$badPing/,@results;





On Fri, 9 Sep 2005 01:41:19 -0700 (PDT), "Christopher Spears"
<[EMAIL PROTECTED]> said:
> I've decided to rework my Perl script that pings a
> blade and checks for nrnode:
> 
> my @bladeNumbers = @ARGV;
> 
> if (scalar @bladeNumbers == 0) {
> print "No blades entered!\n";
> exit;
> }
> 
> foreach $_(@bladeNumbers) {
>my $blade = "blade-".$_; 
>print "$blade\n";
>my $badPing = "Destination Host Unreachable";
>if (`ping $blade` =~ /$badPing/) {print "$blade:
> $badPing\n";}
>my $nrnode = `ssh $blade ps aux | grep nrnode`;
>if ($nrnode =~ /nrnode/) {print "Found nrnode for
> $blade!\n";}
> }
> 
> The problem line is:
> 
> if (`ping $blade` =~ /$badPing/) {print "$blade:
> $badPing\n";}
> 
> How do I go about finding out if the blade I ping is
> not sending back the packets?  From what I can gather,
> ping returns a success regardless of whether or not
> packets are received.
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Access all of your messages and folders
  wherever you are


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




Re: Regex - find chars between ()

2005-09-11 Thread Jeff Pan
Is this feasible?

while(<>)
{
next unless /$host/;
$_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/;
my @array=("$1","$2","$3","$4");
}



On Mon, 12 Sep 2005 16:14:14 +1000, "Keenan, Greg John (Greg)** CTR **"
<[EMAIL PROTECTED]> said:
> Hi,
>  
> Have a file like:
>  
> meteor(L, 4) (G,24)
> rocket(J,19) (D,35)
> aulan (E,28) (E, 2)
> aupbx (B,32) (O,10)
>  
> And I need to work with the chars between the brackets after I've found
> the
> string on the left e.g. if my $host variable matches rocket then I need
> to
> get J and 19 and D and 35 into an array or their own seperate variables.
>  
> I have been going around in circles with the regex.  I have tried
> escaping
> the round brackets with \, anchoring the string to the end with \z and a
> multitude of other combos of \D \d \w . \s etc.
>  
> Note that some coordinates have two digits and others single digit with
> whitespace before it.
>  
> #StartCode
> use strict;
> use warnings;
> use diagnostics;
>  
> my $host = $ARGV[0];
> my $dirRoot = "/gjkeenan/G7";
> my $fileG7 = "$dirRoot/G7";
> my $filePW = "$dirRoot/PW";
>  
> open(PWFILE, "$filePW")
>   || die "Can't open $filePW: $!";
> while () {
>   if (/$host/) {
> my @c = /(\D,\d\d)\s(\D,\d\d)/;
>   }
> }
> close(PWFILE);
> ...do something with $c[0] $c[1] $c[2] $c[3]...
> #EndCode
>  
>  
> Really appreciate some pointers.
> Regards, Greg
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Or how I learned to stop worrying and
  love email again


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




Re: Regex - find chars between ()

2005-09-12 Thread Jeff Pan


Sorry,it should be:
$_=~/\((\w+)\,\s*(\d+)\)\s+\((\w+)\,\s*(\d+)\)/;

Didn't consider the blank space before.

On Mon, 12 Sep 2005 14:54:56 +0800, "Jeff Pan" <[EMAIL PROTECTED]>
said:
> Is this feasible?
> 
> while(<>)
> {
> next unless /$host/;
> $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/;
> my @array=("$1","$2","$3","$4");
> }
> 
> 
> 
> On Mon, 12 Sep 2005 16:14:14 +1000, "Keenan, Greg John (Greg)** CTR **"
> <[EMAIL PROTECTED]> said:
> > Hi,
> >  
> > Have a file like:
> >  
> > meteor(L, 4) (G,24)
> > rocket(J,19) (D,35)
> > aulan (E,28) (E, 2)
> > aupbx (B,32) (O,10)
> >  
> > And I need to work with the chars between the brackets after I've found
> > the
> > string on the left e.g. if my $host variable matches rocket then I need
> > to
> > get J and 19 and D and 35 into an array or their own seperate variables.
> >  
> > I have been going around in circles with the regex.  I have tried
> > escaping
> > the round brackets with \, anchoring the string to the end with \z and a
> > multitude of other combos of \D \d \w . \s etc.
> >  
> > Note that some coordinates have two digits and others single digit with
> > whitespace before it.
> >  
> > #StartCode
> > use strict;
> > use warnings;
> > use diagnostics;
> >  
> > my $host = $ARGV[0];
> > my $dirRoot = "/gjkeenan/G7";
> > my $fileG7 = "$dirRoot/G7";
> > my $filePW = "$dirRoot/PW";
> >  
> > open(PWFILE, "$filePW")
> >   || die "Can't open $filePW: $!";
> > while () {
> >   if (/$host/) {
> > my @c = /(\D,\d\d)\s(\D,\d\d)/;
> >   }
> > }
> > close(PWFILE);
> > ...do something with $c[0] $c[1] $c[2] $c[3]...
> > #EndCode
> >  
> >  
> > Really appreciate some pointers.
> > Regards, Greg
> -- 
>   Jeff Pan
>   [EMAIL PROTECTED]
> 
> -- 
> http://www.fastmail.fm - Or how I learned to stop worrying and
>   love email again
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - The way an email service should be


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




RE: Regex - find chars between ()

2005-09-12 Thread Jeff Pan
> Why are $1, $2, $3, and $4 in quotes? What's
> wrong with this:
> 
> my @array = ( $1, $2, $3, $4 );
> 
> Or this:
> 
> my @array = //;


Sorry, when I use the second way u mentioned,it can't work.

the code:
while(<>)
{
next unless /$host/;
$_=~/\((\w+)\,\s*(\d+)\)\s+\((\w+)\,\s*(\d+)\)/;
#my @array=("$1","$2","$3","$4");
my @array=qw/$1 $2 $3 $4/;
print join (":",@array),"\n";
}

executing the script:
$ perl t10.pl tt2.txt 
$1:$2:$3:$4

why this happen?






On Mon, 12 Sep 2005 02:38:25 -0500, "Charles K. Clarkson"
<[EMAIL PROTECTED]> said:
> Jeff Pan <mailto:[EMAIL PROTECTED]> wrote:
> 
> : Is this feasible?
> 
> Yes, but ...
> 
> 
> : while(<>)
> : {
> : next unless /$host/;
> : $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/;
> 
> What happens if this doesn't match? Then $1, $2,
> $3, and $4 will be unitialized in the next statement.
> Better to check that this match happens.
> 
> : my @array=("$1","$2","$3","$4");
> 
> Why are $1, $2, $3, and $4 in quotes? What's
> wrong with this:
> 
> my @array = ( $1, $2, $3, $4 );
> 
> Or this:
> 
> my @array = //;
> 
> 
> : }
> 
> HTH,
> 
> Charles K. Clarkson
> -- 
> Mobile Homes Specialist
> 254 968-8328
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Send your email first class


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




about utf8

2005-09-14 Thread Jeff Pan
HI,

I want to translate some utf8 characters to appropriate characters.I use
utf8 module,but it seems to work uncorrectly.

This is the code:


use utf8;
#if (utf8::valid($subject))
if (Encode::is_utf8($subject))
{
$subject=utf8::decode($subject);
print $subject,"\n";
}


It seems that the is_utf8() function can't judge the given string is
utf8 or not.

my perl version is 5.8.0.

can anyone give me some advises? thanks.
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - A no graphics, no pop-ups email service


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




Re: keys of hash of hashes

2005-09-16 Thread Jeff Pan
maybe u want this:

foreach my $fileName ( keys %$ref_allTariffData ){

foreach my $name ( keys %{$ref_allTariffData->{$fileName}} ){

 print $name,";";

}
}





On Fri, 16 Sep 2005 10:33:58 +0200, "Brent Clark"
<[EMAIL PROTECTED]> said:
> Hi list
> 
> I have a hash that im trying to get the keys.
> 
> 
> 
> foreach my $fileName ( keys %$ref_allTariffData ){
> 
>   print keys $ref_allTariffData{$fileName};
> 
> }
> 
> 
> My Data Dumper:
> 
> $VAR1 = {
>'sham02' => {
>  'Luxury' => 'LuxRm'
>},
>'kwam01' => {
>  'Thatched Chalet' => 'Chalet',
>  'Luxury Safari Tent' => 'LuxTnt'
>},
> 
> I basically want just:
> 
> Luxury, Thatched Chalet', Luxury Safari Tent etc.
> 
> If anyone would could assist me, I would be most grateful.
> 
> Kind Regards
> Brent Clark
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Same, same, but different�


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




about sleep: is it a bug?

2005-09-20 Thread Jeff Pan
HI,

I found a problem in my script.I call sleep function in a child process
(sleep 3600 sec,then wake up and do something).
But these days I found sleep can't wake up.I checked it carefully,and
find that when sleeping,if disks I/O error occured (such as 100% disks
space using,no free space for writing),the sleep will have something the
matter -- it never wake up from that time.
Is this true?and how can I resolve this problem?tks more.


btw: my codes about sleep are below:


die "can't fork:$!" unless defined (my $child = fork());
if ($child==0)
{
while(1)
{
sleep 3600;
my %total=();
open (HD,$log) or die "can't read from logfile:$!";
while()
{
next if /^$/;
chomp;
my ($mbox_id,$size,$type)=split(/:/,$_);
$total{$mbox_id}{$type}+=$size;
}
close HD;

`cat /dev/null > $log`;

&disable(\%total);
}
}
----------
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Choose from over 50 domains or use your own


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




move applications from traditional CGI to mod_perl

2005-09-23 Thread Jeff Pan
hi,everyone,

I want to move my web applications which written by traditional CGI to
mod_perl.Is there any risk or difficulty here?
The applications are something about webmail.Which module under mod_perl
is suited for me?
Any advise or reference to me should be appreciated.TKS.
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - The professional email service


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




Re: Redirecting STDERR

2005-10-07 Thread Jeff Pan
hi,
maybe u should redefined the __DIE__ handle for the reason of safety.
such as:

$SIG{__DIE__}=\&log_die;
sub log_die
{
open (HDW,">>",$err_log);
select HDW;$|=1;select STDOUT;
print HDW @_;
close HDW;
die @_;
}


2005/10/8, Timothy Johnson <[EMAIL PROTECTED]>:
> It partly depends on your operating system, I think.  That's fine on
> Windows, but on UNIX I think that under some if not all circumstances
> your change will persist after the script finishes executing.  I've
> never had to do it, but I've seen one method that goes like this:
>
> open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
> open(STDERR,">script.err") or die "Failed to redirect STDERR";
>
> do something...
>
> open(STDERR,">&OLD_STDERR") or die "Failed to restore STDERR";
>
>
> -Original Message-
> From: Ryan Frantz [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 07, 2005 12:10 PM
> To: beginners@perl.org
> Subject: Redirecting STDERR
>
> Perlers,
>
> I have a script where I redirect STDERR to a file so that I can capture
> 'die' messages like so:
>
> use warnings;
> use strict;
>
> my $logfile = "/some/path/logfile.txt";
>
> open STDERR, ">>$logfile";
>
> something or die "Unable to do something()\n";
>
> close STDERR;
>
> Is it kosher to do this?  Or is there a more preferred method to
> redirect 'die' messages?
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>

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




compare two files

2005-10-11 Thread Jeff Pan
hi,

Is there a best way to find some lines which exists in both two files?
Someone has show me a method but it seems a little low efficiency.
The code is as below:

open (T1,"1.txt") or die "$!";
open (T2,"2.txt") or die "$!";

while(my $line=){
  chomp $line;
  print $line,"\n" unless diff($line);
}

sub diff
{
   my $line=shift;
   my $ok=0;
   while(){
   chomp;
   if ($_ eq $line)
   {
   $ok=1;
   last;
   }
   }
   return $ok;
}

close T2;
close T1;

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




Re: compare two files

2005-10-11 Thread Jeff Pan
Your code logic says that you want to find lines in '2.txt' that are NOT in
'1.txt'.


thanks for all answerers.
yeah,I have put less attention on that code,and have made a fatal logic error.

but the way mentioned by John, putting file's all contents to a hash,
maybe somewhat less efficiency when the file is large much.is it?

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




difference between '&subroutine()' and 'subroutine()'

2005-10-12 Thread Jeff Pan
HI,

I want to know what's the difference when I call a subroutine with '&'
 or without '&'.
such as:

&subroutine();
sub subroutine{
..
}

or

subroutine();
sub subroutine{
..
}

Can anyone tell me?thanks a lot.

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




how to avoid process die when can't create mysql dbh

2005-10-25 Thread Jeff Pan
hi,

Because of network problem,my script can't create Mysql dbh sometime
when running,then it died.I have written code like this:

my 
$mysql_dbh=DBI->connect("dbi:mysql:$mysql_db:$mysql_host",$mysql_user,$mysql_passwd,
{PrintError => 1,RaiseError => 0});

I want to know how to adjust it,thanks a lot.

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