Re: Chinese word problem
'我' takes 2 bytes '\0' takes 1 byte , so 我“ takes 3 Every chinese charecter takes 2 bytes - Original Message - From: Neil To: beginners@perl.org Sent: Wednesday, May 16, 2007 1:57 PM Subject: Chinese word problem Dear All: Question: How come the length of Chinese word I print shows “ 3 “. Isn’t it supposed to 2 bytes? Program: --- $str=”我”; $str_len = length($str); Print $str_len, “\n\n”; The result is 3 I took a picture for the program. In case of it doesn’t show Chinese word in some of your system, Pls see the attachment My environment: CPU: Intel Pentium C2D T7200 OS: Fedora Core 6 Perl V: 5.8.8 Encode: Big5 Thank you -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Chinese word problem
Thanks for your reply. Excuse me for Further question: What’s the ‘\0’ use for? I got the result of 21 when I put in more Chinese character like: $str=”我 們一起看雲去”; There are 7 Chinese words in the string, Does it mean every single Chinese word have to come with a single ‘\0’? What for? What is the benefit? Thanks again. _ From: Thomas Yan [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 16, 2007 2:14 PM To: Neil; beginners@perl.org Subject: Re: Chinese word problem '我' takes 2 bytes '\0' takes 1 byte , so 我“ takes 3 Every chinese charecter takes 2 bytes - Original Message - From: Neil mailto:[EMAIL PROTECTED] To: beginners@perl.org Sent: Wednesday, May 16, 2007 1:57 PM Subject: Chinese word problem Dear All: Question: How come the length of Chinese word I print shows “ 3 “. Isn’t it supposed to 2 bytes? Program: --- $str=”我”; $str_len = length($str); Print $str_len, “\n\n”; The result is 3 I took a picture for the program. In case of it doesn’t show Chinese word in some of your system, Pls see the attachment My environment: CPU: Intel Pentium C2D T7200 OS: Fedora Core 6 Perl V: 5.8.8 Encode: Big5 Thank you _ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Chinese word problem
Thomas Yan 写道: '我' takes 2 bytes '\0' takes 1 byte , so 我“ takes 3 Not right.This was not like C's char str[] form. I think the origin ppl's words are in some encoding form like base64. For me I got exactly 2 bytes.like, perl -le 'print length(我)' 2 -- Jeff Pang http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Chinese word problem
It's wired! I did the same thing and got the result of 3 perl -le 'print length(我)' 3 Pls see the attachment Thank you. -Original Message- From: Jeff Pang [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 16, 2007 2:40 PM To: Thomas Yan Cc: Neil; beginners@perl.org Subject: Re: Chinese word problem Thomas Yan 写道: '我' takes 2 bytes '\0' takes 1 byte , so 我“ takes 3 Not right.This was not like C's char str[] form. I think the origin ppl's words are in some encoding form like base64. For me I got exactly 2 bytes.like, perl -le 'print length(我)' 2 -- Jeff Pang http://home.arcor.de/jeffpang/ attachment: chineseWord2.JPG-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Chinese word problem
Neil wrote: Dear All: Question: How come the length of Chinese word I print shows “ 3 “. Isn’t it supposed to 2 bytes? Program: --- $str=”我”; $str_len = length($str); Print $str_len, “\n\n”; The result is 3 I took a picture for the program. In case of it doesn’t show Chinese word in some of your system, Pls see the attachment My environment: CPU: Intel Pentium C2D T7200 OS: Fedora Core 6 Perl V: 5.8.8 Encode: Big5 Thank you First, 我 is comes with 2 bytes ASCII 167 + 218 in BIG5 coding. What I would bet the guess is the editor converted something before you run the code or because you are on a *nix platform ( since you heading your script #!/usr/bin/perl , so I assume ) , however I don't familiar with. You may check if there's some Unicode or UTF-8 issues. in UTF-8, there's 3 bytes. You may also check for other words and see if there's still in 3 bytes. HTH, Mug -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Re: output with utf8
Jen mlists 写道: Hello, I need to output contents with utf8 encoding in CGI scripts. Can you tell me how to open STDOUT with utf8 support?Thanks you. Hello, Just do, binmode(STDOUT, :utf8); see perldoc perluniintro for more details. -- Jeff Pang http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Chinese word problem
Neil 写道: It's wired! I did the same thing and got the result of 3 perl -le 'print length(我)' 3 Pls see the attachment How about your shell environment? For me something are: SHELL=/bin/bash LC_ALL=C LANG=en_US.en -- Jeff Pang http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Chinese word problem
On 05/16/2007 12:57 AM, Neil wrote: Dear All: Question: How come the length of Chinese word I print shows “ 3 “. Isn’t it supposed to 2 bytes? Program: --- $str=”我”; $str_len = length($str); Print $str_len, “\n\n”; The result is 3 I took a picture for the program. In case of it doesn’t show Chinese word in some of your system, [...] My environment: [...] Encode: Big5 Something is messed up with your locale or environment. Since you only have one character in $str, the length should be 1--and that's what I get. I saved your program two ways: as a utf8 file and as a big5 file; both programs produce the same result on my system: 1; however, to get your program to run, I had to change the quotes. Here is the first program (saved in UTF8): --- #!/usr/bin/perl use utf8; use strict; use warnings; my $str=我; my $str_len = length($str); print $str_len, \n\n; -- Here is the second program (saved in Big5): #!/usr/bin/perl use encoding big5 = STDOUT = 'utf8'; use strict; use warnings; my $str=§Ú; my $str_len = length($str); print $str_len, \n\n; print data = $str\n; The second program displays this: --start output--- 1 data = 我 ---end output Evidently the Big5 character sequence \xA7\xDA represents the single Unicode character \x6211 which is the Chinese character 我. You probably just need to tell Perl about the encoding of your script. My environment: Perl 5.8.4 Debian 3.1 Encoding: UTF8 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: output with utf8
Hello, Does thie mean when I say, binmode(STDOUT, :utf8); The characters would be translated to utf8 for output automatically? (Would I need to translate them to utf8 firstly before output?) Thanks again. 2007/5/16, Jeff Pang [EMAIL PROTECTED]: Jen mlists 写道: Hello, I need to output contents with utf8 encoding in CGI scripts. Can you tell me how to open STDOUT with utf8 support?Thanks you. Hello, Just do, binmode(STDOUT, :utf8); see perldoc perluniintro for more details. -- Jeff Pang http://home.arcor.de/jeffpang/
Re: Delete a particular line from file
Suppose i have checked the group of I/P addresses for deleting opting then what should i do?? Is there any inbuilt function there for that requirement?? On Tue, 2007-05-15 at 12:25 +0800, Jeff Pang wrote: sivasakthi 写道: Hi, I have used the file in perl, file contains like that, 1176369096.111468 172.16.2.80 TCP_MISS/200 9629 1176378643.614458 172.16.2.80 TCP_MISS/200 9626 1176378681.984662 172.16.2.75 TCP_MISS/200 9626 1176436396.304 1142 172.16.2.80 TCP_MISS/200 13281 1176436397.228916 172.16.2.99 TCP_REFRESH_HIT/200 7521 1176436469.060 1470 172.16.2.80 TCP_MISS/200 5822 I have need to split the each column in to separate hash value,before that i need to delete the particular user details from the file.For example if a line contains the user I/P of 172.16.2.80 then i should delete that whole line and then split in to separate column. For that what should i do?? while(FILE) { my ($time,$lport,$ip,$stats,$rport) = split; next if $ip eq '172.16.2.80'; # using those values above to create hash,based on what form of hash you needed. }
Re: Delete a particular line from file
sivasakthi 写道: Suppose i have checked the group of I/P addresses for deleting opting then what should i do?? We don't know what you should do.Only you yourself could konw what you should do.Can you describe the questions more clearly? -- Jeff Pang http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
applying a regular expression on the continuous output of ping command
Hi, ping geekcrossing.net|perl -le m/time=(\d+)/;print $1; Can some one help me with the above command -srini -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Net::Telnet --help required
Hello, I am trying to telnet to all m/c for which i haven't set password(only root is a valid user) any body can telnet using root user But when i try to access through perl it snip use warnings; use Net::Telnet; my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/'); my @line; $t-open(host1); $t-waitfor('/login:.*$/'); $t-print(root); $forecast=$t-print(/usr/bin/ls); print $forecast; O/P : 1 OR use warnings; use Net::Ping; use Net::Telnet; my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/'); my @line; $t-open(host1); $t-login(root,); $result=$t-cmd(/usr/bin/ls); print $result; O/P : timed-out waiting for password prompt at j.pl line 8 Please, help me to understand the solution of it. I need this as urgent requirement for house-keeping activities Thanks in adavance _abhi
missing something from regex ...
Hi i have the following string I need to break down into usable data ... CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 and I dont want Wed May 16 11:24:37 2007 cause the number at the end is the same thing .. this is the beginning of my code ... $row = CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 $row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/ print info $1 \n; print hostname $2 \n; print pubip $3 \n; print wanip $4 \n; print recieved $5 \n; print sent $6 \n; print time $7 \n; and I'm getting the following error .. [EMAIL PROTECTED] ~]# ./vpninfo.pl ./vpninfo.pl: line 1: =: command not found ./vpninfo.pl: line 2: syntax error near unexpected token `(' ./vpninfo.pl: line 2: `$row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/' [EMAIL PROTECTED] ~]# what have I missed ... Many thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
YARQ: Yet Another Regex Question
I have a trouble ticket application that uses a regex to find a piece of information in an incoming email and auto populate a field if it is found. The line it will be looking for is CUSTOMER ENVIRONMENT customer_name where customer_name will never have a space making it one word. If I just want to pull from the line the customer_name would my regex look like $MatchString = CUSTOMER ENVIRONMENT\s+(\w) For what it's worth the line that will handle this is $found = ($Transaction-Attachments-First-Content =~ /$MatchString/m); I'm guessing that when used in an assignment like this, $1 will be used as the value. The contents of (\w) in this case. Is that correct? Mathew -- Keep up with me and what I'm up to: http://theillien.blogspot.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: YARQ: Yet Another Regex Question
On 5/16/07, Mathew Snyder [EMAIL PROTECTED] wrote: I have a trouble ticket application that uses a regex to find a piece of information in an incoming email and auto populate a field if it is found. The line it will be looking for is CUSTOMER ENVIRONMENT customer_name where customer_name will never have a space making it one word. If I just want to pull from the line the customer_name would my regex look like $MatchString = CUSTOMER ENVIRONMENT\s+(\w) Bad idea. Use qr() instead. For what it's worth the line that will handle this is $found = ($Transaction-Attachments-First-Content =~ /$MatchString/m); I'm guessing that when used in an assignment like this, $1 will be used as the value. The contents of (\w) in this case. Is that correct? snip Yes, the $1 match variable will hold the match if $found is true. A common idiom is therefore my $name; my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; if ($Transaction-Attachments-First-Content =~ /$regex) { $name = $1; } else { die could not find name; } Another way to write this is my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; my ($name) = $Transaction-Attachments-First-Content =~ /$regex/ or die could not find name; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: missing something from regex ...
On 5/16/07, Gregory Machin [EMAIL PROTECTED] wrote: Hi i have the following string I need to break down into usable data ... CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 snip Right, you have delimited data and it looks like there is no chance of the delimiter being part of a field. This means you want the split function, not a regex. snip $row = CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 $row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/ snip These lines are missing semicolons. snip and I'm getting the following error .. [EMAIL PROTECTED] ~]# ./vpninfo.pl ./vpninfo.pl: line 1: =: command not found ./vpninfo.pl: line 2: syntax error near unexpected token `(' ./vpninfo.pl: line 2: `$row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/' [EMAIL PROTECTED] ~]# what have I missed ... snip It looks like you are missing the #!/usr/bin/perl at the beginning of the script and therefore your current shell is being used as the interpreter. Try the following instead: #!/usr/bin/perl use strict; use warnings; my $input = CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477; my ($info, $host, $pubid, $wanip, $recieved, $sent, undef, $time) = split /,/, $input; print info = $info\nhost=$host\npubid=$pubid\nwanip=$wanip\n, recieved=$recieved\nsent=$sent\ntime=$time\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: missing something from regex ...
Gregory Machin wrote: $row = CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 $row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/ print info $1 \n; print hostname $2 \n; print pubip $3 \n; print wanip $4 \n; print recieved $5 \n; print sent $6 \n; print time $7 \n; and I'm getting the following error .. [EMAIL PROTECTED] ~]# ./vpninfo.pl ./vpninfo.pl: line 1: =: command not found ./vpninfo.pl: line 2: syntax error near unexpected token `(' ./vpninfo.pl: line 2: `$row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/' [EMAIL PROTECTED] ~]# what have I missed ... Looks like you are missing semicolons after your first two lines. -m -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: applying a regular expression on the continuous output of ping command
On 5/16/07, Srinivainputs [EMAIL PROTECTED] wrote: Hi, ping geekcrossing.net|perl -le m/time=(\d+)/;print $1; Can some one help me with the above command Add an n to the perl arguments to get it loop over stdin and use single quotes to prevent shell from trying to interpolate $1. ping geekcrossing.net|perl -nle 'm/time=(\d+)/;print $1'; Also, you should probably write it like this: ping geekcrossing.net|perl -nle 'print /time=([\d.]+)/ ? $1 : time not found'; or this ping geekcrossing.net|perl -nle 'print $1 if /time=([\d.]+)/'; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Delete a particular line from file
On 5/16/07, sivasakthi [EMAIL PROTECTED] wrote: Suppose i have checked the group of I/P addresses for deleting opting then what should i do?? Is there any inbuilt function there for that requirement?? snip while(FILE) { my ($time,$lport,$ip,$stats,$rport) = split; next if $ip eq '172.16.2.80'; # using those values above to create hash,based on what form of hash you needed. } Assuming that you have a list of IP addresses you want to skip in @ip, you could say #!/usr/bin/perl use strict; use warnings; OUTER: while(FILE) { my ($time, $lport, $ip, $stats, $rport) = split; for my $skip_ip (@ip) { next OUTER if $ip eq $skip_ip; } # using those values above to create hash #based on what form of hash you needed. } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: transform one2many table
On 5/15/07, yitzle [EMAIL PROTECTED] wrote: snip You can split the input file into chunks, or process one ID and then let the variable go out of scope or whatever... snip Or, since the solution involves hashes, you could use a dbm file tie'd to a hash to keep the data on disk instead of RAM. Take a look at AnyDBM_File*, DBM::Deep*, or the dbmopen* function. * http://search.cpan.org/~nwclark/perl-5.8.8/lib/AnyDBM_File.pm * http://search.cpan.org/~rkinyon/DBM-Deep-1.0001/lib/DBM/Deep.pod * http://www.perl.com/doc/manual/html/pod/perlfunc/dbmopen.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Net::Telnet --help required
On 5/16/07, a b [EMAIL PROTECTED] wrote: Hello, I am trying to telnet to all m/c for which i haven't set password(only root is a valid user) any body can telnet using root user But when i try to access through perl it snip use warnings; use Net::Telnet; my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/'); my @line; $t-open(host1); $t-waitfor('/login:.*$/'); $t-print(root); $forecast=$t-print(/usr/bin/ls); print $forecast; O/P : 1 OR use warnings; use Net::Ping; use Net::Telnet; my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/'); my @line; $t-open(host1); $t-login(root,); $result=$t-cmd(/usr/bin/ls); print $result; O/P : timed-out waiting for password prompt at j.pl line 8 Close. You do the login correctly in example 1, but then you use print to issue the command. all that does is print the string /usr/bin/ls\n to the remote terminal and return 1 to let you know the command succeeded. If you want the output of the remote command, you need to use cmd (in list context) In example 2, you don't pass a password to login or waitfor one, so you never login. You do, though, use cmd, which is what you want, although you need list context: $t-open(host1); $t-waitfor('/login:.*$/'); $t-print(root); my @forecast=$t-cmd(/usr/bin/ls); my $scalar_forecast = join , @forecast; # or join'\n', I don't remember if cmd returns newlines or not HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Can't sort error out; strict refs
Rob Dixon wrote: Mathew Snyder wrote: I'm passing two hash references into a subroutine. One hash is in the format of $dept{$env}{$user}. This contains an amount of time spent by each user on a customer ($env). The second hash is in the format of $ticCount{$env}{$user}{$ticID}. This contains a running count of how many times a user worked on ticket '$ticID' which belongs to customer '$env'. I won't be using that number though. What I need is the number of tickets worked on so I simply use 'scalar keys' on this hash. The problem I'm encountering though, is that I'm passing the hashes into my subroutine as references. When I get to the statement that gets the key count I get an error: Can't use string (2) as a HASH ref while strict refs in use at user_timesheet.pl line 63. Presumably, 2 is the number of keys at $ticCount{$env}{$user}{$ticID}. sub average { my ($users, $count) = @_; my %userAvg; foreach my $env (keys %$count) { foreach my $user (keys %{ $count-{$env} }) { foreach my $ticID (keys %{ $count-{$env}-{$user} }) { my $ticCount = scalar keys %{$count-{$env}-{$user}-{$ticID}}; my @meantemp; my @meantime; my @endtime; my $temp = $users-{$env}-{$user}; @meantemp= split /\./, ($temp / $ticCount); # If the time divided by the number of tickets has a decimal # value round up if that value is greater than # 0.5. This will give an even number of minutes to figure # out the mean time with. if ($meantemp[1]) { if ($meantemp[1] = 5) { $meantemp[0]++; } } @meantime = split /\./, ($meantemp[0] / 60); $endtime[0] = $meantime[0]; $endtime[1] = $meantemp[0] % 60; $userAvg{$env}{$user} = sprintf '%d:%02d', @endtime[0,1]; } } } return %userAvg; } I've run this in the debugger and when I get to the line which assigns $ticCount I try to print it out and it's just blank. If I keep hitting enter it just returns to a blank line. I get the error when I continue to the next line with 'c'. Hi Mathew First of all, you can replace $count-{$env}-{$user}-{$ticID} with $count-{$env}{$user}{$ticID} and Perl will infer the indirection. It makes for neater code. The reason for your problem is that you've gone too far down in the hash structure. You said that $count-{$env}{$user}{$ticID} is a count of how many times a user worked on [a] ticket, in this case 2. so you're then trying to do my $ticCount = scalar keys %{2}; which is failing. Finally, you can round more efficiently by using int(x + 0.5). I suggest something like this (untested): sub average { my ($users, $count) = @_; my %userAvg; foreach my $env (keys %$count) { foreach my $user (keys %{ $count-{$env} }) { my $ticCount = scalar keys %{$count-{$env}{$user}}; my $time = $users-{$env}{$user}; my $meantime = int($time / $ticCount + 0.5); $userAvg{$env}{$user} = sprintf '%d:%02d', int($meantime / 60), $meantime % 60; } } return %userAvg; } HTH, Rob Thanks. That did the trick. I'll be working with your provided method for rounding up tonight when I get to work. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: YARQ: Yet Another Regex Question
Chas Owens wrote: On 5/16/07, Mathew Snyder [EMAIL PROTECTED] wrote: I have a trouble ticket application that uses a regex to find a piece of information in an incoming email and auto populate a field if it is found. The line it will be looking for is CUSTOMER ENVIRONMENT customer_name where customer_name will never have a space making it one word. If I just want to pull from the line the customer_name would my regex look like $MatchString = CUSTOMER ENVIRONMENT\s+(\w) Bad idea. Use qr() instead. For what it's worth the line that will handle this is $found = ($Transaction-Attachments-First-Content =~ /$MatchString/m); I'm guessing that when used in an assignment like this, $1 will be used as the value. The contents of (\w) in this case. Is that correct? snip Yes, the $1 match variable will hold the match if $found is true. A common idiom is therefore my $name; my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; if ($Transaction-Attachments-First-Content =~ /$regex) { $name = $1; } else { die could not find name; } Another way to write this is my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; my ($name) = $Transaction-Attachments-First-Content =~ /$regex/ or die could not find name; What does gr() do? Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: YARQ: Yet Another Regex Question
On 5/16/07, Mathew [EMAIL PROTECTED] wrote: snip What does gr() do? Mathew qr not gr. It is the quote regex operator. from perldoc perlop qr/STRING/imosx This operator quotes (and possibly compiles) its STRING as a regular expression. STRING is interpolated the same way as PATTERN in m/PATTERN/. If ' is used as the delimiter, no interpolation is done. Returns a Perl value which may be used instead of the corresponding /STRING/imosx expression. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: YARQ: Yet Another Regex Question
Mathew 写道: What does gr() do? It's qr not gr. See perldoc perlop and look for qr/STRING/imosx. -- http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: YARQ: Yet Another Regex Question
Chas Owens wrote: On 5/16/07, Mathew [EMAIL PROTECTED] wrote: snip What does gr() do? Mathew qr not gr. It is the quote regex operator. from perldoc perlop qr/STRING/imosx This operator quotes (and possibly compiles) its STRING as a regular expression. STRING is interpolated the same way as PATTERN in m/PATTERN/. If ' is used as the delimiter, no interpolation is done. Returns a Perl value which may be used instead of the corresponding /STRING/imosx expression. Ahh, yes that would certainly work better. One of my concerns was using a bare string containing a space. While it may not break it could cause problems down the road. Something I'd like to avoid. Thanks Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Net::Ping Bug found?
Hi there! I am using Net::Ping on AIX (here 5.2) and I noticed a strange behaviour concerning the ICMP Payload Data Field. If I do a typical default ping with $p = new Net::Ping('icmp', $ping_timeout); I will get a EthernetII-IP-ICMP-Package (so far so good), but this package does not contain a Payload field (I would normaly expect), therefor it contains a Ethernet II Trailer (Wireshark). (I verified this by using iptrace v2.0 on aix and wireshark on my win2k desktop box.) If I do a ping with a manuell specified payload (like $p = new Net::Ping('icmp', $ping_timeout, 18);) the package looks (for me as a halfaway network geek) good. When is this a problem? It looks like some Router (by some Vendors) do not send icmp echo replies on such kind of requests. Sometimes it might look like that your router is down, but it isn´t. (And If you have like me over 1000 multivendor routers/switche/etc to manage, it´s not funny.) What could be the Problem: The package building process in Net::Ping is filthy- I guess the IP-Total Length field is not set correctly (the payload lenght is not added to it). So Please: Could somebody verify this on her/his own System? If anybody feels able or have time to patch this, please patch the multithreadsupport patch right with it. (https://rt.cpan.org/Public/Bug/Display.html?id=4170) If you need to verify the fix feel free to ask me. Bastian Angerstein -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: xterm fonts
On 05/15/2007 04:38 PM, Deboo ^ wrote: I installed a minimal X sysetm with fluxbox and xterm and two other terminal emulators: eterm and mrxvt. But all three of them give very small fonts. WIth xterm, I was able to get a reasonable font with the HUGE option in the right-click menu but I need bigger fonts. How do you exactly specify bigger fonts with xterm? I am aware it's possible with -f or -fn option but what comes after that? Say I wan a 10x20 font? it doesn't work just by typing -f 10x20 I use rxvt, so I'd use this: rxvt -fn 10x20 Back when I was using Eterm, I think I did this: Eterm -F 10x20 And how do you incorporate the custom xterm options in the default fluxbox menu? Is there something to edit the menu commands? Fluxbox is based on blackbox, and blackbox menu file is in ~/.blackbox/menu, so you might have to edit ~/.fluxbox/menu. I don't know of a menu editing utility for blackbox/fluxbox; just edit the text menu file. Also how to use the dektop icons that DSL is able to use with fluxbox? I already installed fbdesk but it seems of no use at all or is it buggy? Regards, Deboo I don't know anything about the icons. For setting fonts in terminal emulators, read the associated manual pages and the documentation in /usr/share/doc/program. You can get a list of fonts that should work properly by typing xlsfonts | less. You probably don't need to modify the menu to get mrxvt to change its look. If it's anything like rxvt, you can use X resources to configure it: FILE name=~/.Xdefaults mrxvt*font:10x20 /FILE Execute this before starting mrxvt: xrdb -merge ~/.Xdefaults I hope this helps. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Net::Ping Bug found?
On 5/16/07, Angerstein [EMAIL PROTECTED] wrote: So Please: Could somebody verify this on her/his own System? I'm sure that many people will be glad to help you. Could you please supply a small program that testers could run and send you the output? Good luck with your project! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: applying a regular expression on the continuous output of ping command
Something like this: ping geekcrossing.net | perl -nle 'print $1 if /time=(\d+\.\d+)/' HTH Goran -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
AW: Net::Ping Bug found?
I can hand my Routine to you people. Use: Start iptrace with iptrace -i en1 -S 1500 -P ICMP /tmp/trace.bin (when you kill iptrace use kill -15 important!!!) Use this code # use Net::Ping; my $p; # Ping Objekt my $r = 127.0.0.1; # Give any IP address $p = new Net::Ping('icmp', 5); #or #$p = new Net::Ping('icmp', 5, 18); # Paketlaenge 60 Byte # tcpdump -I -i en1 -s 200 -e| grep -i icmp my $ping_elapsed = time(); $status = $p-ping($r); $ping_elapsed = time() - $ping_elapsed; return $status; ### Stop iptrace (like i said with kill -15) Start it with iptrace -i en1 -S 1500 -P ICMP /tmp/trace_payload.bin To get annother file. Use this code # use Net::Ping; my $p; # Ping Objekt my $r = 127.0.0.1; # Give any IP address #$p = new Net::Ping('icmp', 5); #or $p = new Net::Ping('icmp', 5, 18); # Paketlaenge 60 Byte # tcpdump -I -i en1 -s 200 -e| grep -i icmp my $ping_elapsed = time(); $status = $p-ping($r); $ping_elapsed = time() - $ping_elapsed; return $status; ### Stop iptrace. Post the .bin files you got from iptrace. Post what system/os was used. Thanks!! You can open the files with wireshark or ethereal. -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Tom Phoenix Gesendet: Mittwoch, 16. Mai 2007 18:38 An: Angerstein Cc: beginners@perl.org; [EMAIL PROTECTED]; [EMAIL PROTECTED] Betreff: Re: Net::Ping Bug found? On 5/16/07, Angerstein [EMAIL PROTECTED] wrote: So Please: Could somebody verify this on her/his own System? I'm sure that many people will be glad to help you. Could you please supply a small program that testers could run and send you the output? Good luck with your project! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: xterm fonts
On 05/15/2007 07:04 PM, Mumia W.. wrote: On 05/15/2007 04:38 PM, Deboo ^ wrote: I installed a minimal X sysetm with fluxbox and xterm and two other [...] Sorry, wrong list :-( -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Net::Ping Bug found?
On 5/16/07, Angerstein [EMAIL PROTECTED] wrote: Start iptrace with Machine #1: Doesn't have iptrace. OpenBSD 4.0 system. Machine #2: Doesn't have iptrace. MacOS X 10.4.9. I hope that other testers have better results for you! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Inconsistent results from file test (-X) operators
Dear Folks, I have encountered inconsistent behaviour with the file test (-X) operators. I am using perl, v5.8.8 built for i486-linux-gnu-thread-multi on a Kubuntu Feisty system. I show below my minimal test file: --- Minimal Test File --- #!/usr/bin/perl -w use diagnostics; # Minimal example for problem with file test, or -X, operators $testdir = /usr; opendir(DH, $testdir) or die Could not open $testdir: $!\n; while (defined($file = readdir(DH))) { if (-d $file) { print $file is a directory\n; } elsif (-f $file) { print $file is a regular file\n; } else { print $file is neither a directory nor a regular file\n; } } closedir(DH); - The results I get are: - include is a directory src is a directory lib is a directory sbin is neither a directory nor a regular file bin is a directory local is neither a directory nor a regular file lib32 is neither a directory nor a regular file games is neither a directory nor a regular file share is neither a directory nor a regular file . is a directory .. is a directory lib64 is neither a directory nor a regular file X11R6 is neither a directory nor a regular file - and ls -al /usr gives: - drwxr-xr-x 13 root root 4096 2007-05-15 16:18 . drwxr-xr-x 23 root root 4096 2007-05-15 00:55 .. drwxr-xr-x 2 root root 69632 2007-05-17 00:12 bin drwxr-xr-x 2 root root 4096 2007-05-15 08:45 games drwxr-xr-x 35 root root 4096 2007-05-15 16:10 include drwxr-xr-x 149 root root 69632 2007-05-16 14:33 lib drwxr-xr-x 3 root root 4096 2007-05-15 01:33 lib32 drwxr-xr-x 3 root root 4096 2007-05-15 16:18 lib64 drwxr-xr-x 10 root root 4096 2007-04-17 13:19 local drwxr-xr-x 2 root root 12288 2007-05-17 00:12 sbin drwxr-xr-x 244 root root 12288 2007-05-16 13:55 share drwxrwsr-x 4 root src 4096 2007-04-17 13:23 src drwxr-xr-x 3 root root 4096 2007-04-17 13:21 X11R6 - Can anyone please tell me why I get this inconsistent behaviour and how to overcome it? I have read of the possibility of a race condition with these operators but I am unsure whether it applies here. Thank you. Chandra 17 May 07 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Inconsistent results from file test (-X) operators
On 5/16/07, R (Chandra) Chandrasekhar [EMAIL PROTECTED] wrote: snip Can anyone please tell me why I get this inconsistent behaviour and how to overcome it? snip It is not inconsistent, you are using file names without the proper path. If a file or directory exists in the current directory with the same name as one in /usr you will get a result, otherwise there is no file, so you are told false for both. You can fix your code by either prefixing the file name with the directory or doing chdir() into $testdir. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Inconsistent results from file test (-X) operators
R (Chandra) Chandrasekhar wrote: Dear Folks, Hello, I have encountered inconsistent behaviour with the file test (-X) operators. I am using perl, v5.8.8 built for i486-linux-gnu-thread-multi on a Kubuntu Feisty system. I show below my minimal test file: --- Minimal Test File --- #!/usr/bin/perl -w use strict; use diagnostics; # Minimal example for problem with file test, or -X, operators $testdir = /usr; opendir(DH, $testdir) or die Could not open $testdir: $!\n; while (defined($file = readdir(DH))) { if (-d $file) perldoc -f readdir readdir DIRHANDLE Returns the next directory entry for a directory opened by opendir. If used in list context, returns all the rest of the entries in the directory. If there are no more entries, returns an undefined value in scalar context or a null list in list context. If you’re planning to filetest the return values out of a readdir, you’d better prepend the directory in question. Otherwise, because we didn’t chdir there, it would have been testing the wrong file. opendir(DIR, $some_dir) || die can’t opendir $some_dir: $!; @dots = grep { /^\./ -f $some_dir/$_ } readdir(DIR); closedir DIR; So: if (-d $testdir/$file) { print $file is a directory\n; } elsif (-f $file) And: elsif (-f $testdir/$file) Or more simply: elsif (-f _) { print $file is a regular file\n; } else { print $file is neither a directory nor a regular file\n; } } closedir(DH); John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Chinese word problem
I did check the environment, And set the same settings like your's, But the result still got 3 Some thing different is that there are some warring from perl, And I have no clue how to deal with it. Thanks [EMAIL PROTECTED] perlPratice]# set | grep SHELL SHELL=/bin/bash SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments: monitor [EMAIL PROTECTED] perlPratice]# set | grep LC_ALL LC_ALL=C [EMAIL PROTECTED] perlPratice]# set | grep LANG LANG=en_US.en [EMAIL PROTECTED] perlPratice]# perl -le 'print length(我)' perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = en_US.en are supported and installed on your system. perl: warning: Falling back to the standard locale (C). 3 [EMAIL PROTECTED] perlPratice]# --- -Original Message- From: Jeff Pang [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 16, 2007 3:22 PM To: Neil Cc: 'Thomas Yan'; beginners@perl.org Subject: Re: Chinese word problem Neil 写道: It's wired! I did the same thing and got the result of 3 perl -le 'print length(我)' 3 Pls see the attachment How about your shell environment? For me something are: SHELL=/bin/bash LC_ALL=C LANG=en_US.en -- Jeff Pang http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Chinese word problem
Neil 写道: I did check the environment, And set the same settings like your's, But the result still got 3 Some thing different is that there are some warring from perl, And I have no clue how to deal with it. Thanks [EMAIL PROTECTED] perlPratice]# set | grep SHELL SHELL=/bin/bash SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments: monitor [EMAIL PROTECTED] perlPratice]# set | grep LC_ALL LC_ALL=C [EMAIL PROTECTED] perlPratice]# set | grep LANG LANG=en_US.en [EMAIL PROTECTED] perlPratice]# perl -le 'print length(我)' perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = en_US.en are supported and installed on your system. perl: warning: Falling back to the standard locale (C). 3 [EMAIL PROTECTED] perlPratice]# Ok you can IM me if you'd like,let me see what happened actually on your end.my aim: pangjr -- http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/