Re: split based on n number of occurances of a character
using a regex is may suitable. $ perl -e '$x= a;b;c;d;e;f;g;h;@re=$x=~/(\w+;\w+);{0,1}/g;print @re' a;b c;d e;f g;h On 10/26/07, Mahurshi Akilla [EMAIL PROTECTED] wrote: Is there an easy way (without writing our own proc) to split a string based on number of occurances of a character ? for example: $my_string = a;b;c;d;e;f;g;h @regsplitarray = split (/;/, $my_string) splits based on every 1 occurance of ; what if i want it to do 2 at a time ? e.g. $regsplitarray[0] = a;b .. $regsplitarray[1] = c;d .. and so on.. In this example, I used 2.. It could be n in general. Is there a way to do this without writing our own procedure ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Absolute noobie question regarding opening files on Windows platform
On Oct 23, 6:55 pm, [EMAIL PROTECTED] (Paul Lalli) wrote: On Oct 22, 3:27 pm, [EMAIL PROTECTED] (Ayesha) wrote: Hi all I wrote this code to read a file (in the same directory as the script) on Win XP *** #!/usr/local/bin/perl use strict; use warnings; open(READFILE1,./Sample_text_file.txt) or die (Cannot open the given file); my $record; while ($record = READFILE1) { print $record; } close READFILE1; #print Is this even working? \n **** It is gives me output that Cannot open the given file. However, the same program is working on linux/mac platforms, i.e. can open files and read them. To check that I have perl correctly installed I added a print statement at the end. When I block everything regarding opening the file and just have the print statement in the script, the script works OK, implying Perl is installed correctly. Can anyone tell me what is wrong. Can anyone tell me what am I doing wrong here? It seems some Windows specific thing. You are asking *us* why Perl can't open the file, before you ask *Perl* why it can't open the file. That is most illogical... Your die() message should include the $! variable, which contains the last operating system error. It will tell you why the file could not be opened. Change your die() to: die Cannot open the given file: $!; Not relevant to the problem at hand, but you should also be using lexical filehandles instead of global barewords, and get into the habbit of using the three-argument form of open: open my $READFILE1, '', './Sample_text_file.txt' or die Cannot open the given file: $!; Paul Lalli- Hide quoted text - - Show quoted text - Some suggestions: 1. Instead of using $! for displaying error messages, use $^E. U will get more descriptive error messages. 2. Quickly going thru this digest i observerd usage of '\' in double quotes, this is not recommended. always escape '\' in double quotes like this \\. Heres an example where things can go wrong, lets say ur file/directory name starts with 'n' and u say somthing like open FILE, .\newFile; \n is interpreted as special character by perl or for that matter any other language. Correct way would be open FILE, .\\newFile; ~emptee. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
packing a C structure
hi,, iam new to perl..i would like to pack a C structure to send it via socket this is my C structure typedef struct buffer_t { uint32_t a; char b[16]; uint32_t c; uint32_t d; char e[6]; char f[8]; } buffer_t; can u provide a guideline for the format in the Pack command that i need to use... Thanks Regards Rams -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
how to print dual key hash..
I have the fallowing code segment in my code. I want to print my %termWeightHash to see if i have correct data at the end of the this computation. Since this hash has two keys(I guess way to think that is hash within) I am not sure how to print it.. regular one key has i could print like this... while (($key, $value) = each(%termWeightHash) ) { print $key = $value\n; } foreach $document(@documents){ $valueOfTermD = 0; $powerOfTermD = 0; foreach $term(keys %termWeightHash){ if($termWeightHash{$term}{$document}){ $powerOfTermD = $powerOfTermD + $termWeightHash{$term}{$document}* $termWeightHash{$term}{$document}; } } $valueOfTermD = sqrt($powerOfTermD); $hashTermD{$document} = $valueOfTermD; } thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
$SIG return to default
I need to use $SIG to modify the behavior of die in a portion of my code. The module I am calling uses die instead of returning a certain error, that I EXPECT to encounter. So, I can do this $SIG{_ _DIE_ _} = sub { my $message = shift; print STDOUT Script died with this message:\n; print STDOUT $message\n; }; However, I only want this modified behavior in one small section of the code. How do I return the behavior to it's default? Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $SIG return to default
use local,like: { # in a code block local $SIG{__DIE__} = sub { }; do something... } when code run out of the block,$SIG{__DIE__} will restore to its default value. On 10/26/07, dolfantimmy [EMAIL PROTECTED] wrote: I need to use $SIG to modify the behavior of die in a portion of my code. The module I am calling uses die instead of returning a certain error, that I EXPECT to encounter. So, I can do this $SIG{_ _DIE_ _} = sub { my $message = shift; print STDOUT Script died with this message:\n; print STDOUT $message\n; }; However, I only want this modified behavior in one small section of the code. How do I return the behavior to it's default? Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Separating the body of the text in email from its header
The usually the format of the mail will be HEADER1 HEADER2 HEADER3 .. .. .. HEADERn BODY Please note there will be a blank line b/w the end of the header and the body. So you start from the beginning of the mail and keep ignoring the lines until you find a blank line The rest of it would be the body. Thanks Prasanna -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, October 26, 2007 2:42 PM To: beginners@perl.org Subject: Separating the body of the text in email from its header Hi, I need a urgent help How can we separate the body of the text in an email from its header? Regards, Praveena -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Separating the body of the text in email from its header
On 10/26/07, Praveena Vittal [EMAIL PROTECTED] wrote: Hi, I need a urgent help How can we separate the body of the text in an email from its header? This is not easy to do it by hand,you must be pretty much familiar with RFC822 and 2822. Luckly there's already a module on cpan which may help you: http://search.cpan.org/~doneill/MIME-tools-5.423/lib/MIME/Parser.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how to print dual key hash..
On 10/26/07, newBee [EMAIL PROTECTED] wrote: I have the fallowing code segment in my code. I want to print my %termWeightHash to see if i have correct data at the end of the this computation. Since this hash has two keys(I guess way to think that is hash within) I am not sure how to print it.. If you only want to see if the data stru is correct or not,you can use Data::Dumper. use Data::Dumper; print Dumper \%termWeightHash; If you want to loop through a HoH,you can do something like: use strict; use warnings; my %hash = ( 'keya' = { 'keya0' = 1 }, 'keyb' = { 'keyb0' = 2, 'keyb1' = 3 }, ); for my $k1 (keys %hash) { for my $k2 (keys %{$hash{$k1}}) { print $k1 - $k2 - ,$hash{$k1}{$k2},\n; } } __END__ see `perldoc perldata` for full details. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to keep working after restarting the host
On 10/26/07, Cheellay Zen [EMAIL PROTECTED] wrote: Hello, I need to restart the host several times in the process of my script, and I'd like the script to keep working after restarting, How can I do this? Hi, You may consider to use a local file for record the current process case (including process logic and datas).After restarting,read the before case from the file and continue the unfinished logic,if it's possible. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Separating the body of the text in email from its header
Hi, I need a urgent help How can we separate the body of the text in an email from its header? Regards, Praveena -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Separating the body of the text in email from its header
Thanks for your suggestion. Nagasamudram, Prasanna Kumar wrote, On 10/26/2007 02:51 PM: The usually the format of the mail will be HEADER1 HEADER2 HEADER3 .. .. .. HEADERn BODY Please note there will be a blank line b/w the end of the header and the body. So you start from the beginning of the mail and keep ignoring the lines until you find a blank line The rest of it would be the body. Thanks Prasanna -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, October 26, 2007 2:42 PM To: beginners@perl.org Subject: Separating the body of the text in email from its header Hi, I need a urgent help How can we separate the body of the text in an email from its header? Regards, Praveena -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
How to keep working after restarting the host
Hello, I need to restart the host several times in the process of my script, and I'd like the script to keep working after restarting, How can I do this? Thanks, Cheellay Zen
Re: packing a C structure
On 10/26/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: can u provide a guideline for the format in the Pack command that i need to use... Hi, Consider to read `perldoc -f pack` at first which maybe will help you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
split based on n number of occurances of a character
Is there an easy way (without writing our own proc) to split a string based on number of occurances of a character ? for example: $my_string = a;b;c;d;e;f;g;h @regsplitarray = split (/;/, $my_string) splits based on every 1 occurance of ; what if i want it to do 2 at a time ? e.g. $regsplitarray[0] = a;b .. $regsplitarray[1] = c;d .. and so on.. In this example, I used 2.. It could be n in general. Is there a way to do this without writing our own procedure ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
On 10/26/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Hi All, I am executing my $usr=qx(who am i); to get the user id on unix machine but it is giving error. sh: who am i: not found Oops,it's `whoami` not `who am i` unless you have aliased it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: back slash problem
On Oct 4, 5:19 pm, [EMAIL PROTECTED] (Praveena Vittal) wrote: Hi All, I need a way to replace a backslash(ie:\) with \\ in a string. Please help me... eg:ssh\[[\d]*\] from [\d\.]* consider the string Regards, Praveena $srt =~s/\\//g; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
how to print dual key hash..
I have the fallowing code segment in my code. I want to print my foreach $document(@documents){ $valueOfTermD = 0; $powerOfTermD = 0; foreach $term(keys %termWeightHash){ if($termWeightHash{$term}{$document}){ $powerOfTermD = $powerOfTermD + $termWeightHash{$term}{$document}* $termWeightHash{$term}{$document}; } } $valueOfTermD = sqrt($powerOfTermD); $hashTermD{$document} = $valueOfTermD; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
On 26 Oct 2007 at 19:14, Jeff Pang wrote: On 10/26/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Hi All, I am executing my $usr=qx(who am i); to get the user id on unix machine but it is giving error. sh: who am i: not found Oops,it's `whoami` not `who am i` unless you have aliased it. I don't know: -bash-3.00$ who am i dpaikkos pts/14 Oct 26 12:16 (host.mydomain.com) Work for me on a bash shell as does whoami. Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
error in qx
Hi All, I am executing my $usr=qx(who am i); to get the user id on unix machine but it is giving error. sh: who am i: not found Please guide how to resolve this Thanks Irfan.
RE: error in qx
Thanks for replying to this mail. Now I need to write a regular expression so that I only get username from the output of this command. So I have written like this. my $usr=`who am i`; $usr=~ m{(.+)\s$}; print $usr\n; But still I am not getting only username. Please guide. Regards Irfan. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Pang Sent: Friday, October 26, 2007 4:54 PM To: Beginner Cc: beginners @ perl. org Subject: Re: error in qx On 10/26/07, Beginner [EMAIL PROTECTED] wrote: -bash-3.00$ who am i dpaikkos pts/14 Oct 26 12:16 (host.mydomain.com) Work for me on a bash shell as does whoami. No. You're actually executing the `who` command,which just take the `am i` as its arguments. The results are the same: $ who am i pyh pts/0Oct 26 18:48 (116.21.60.xx) $ who pyh pts/0Oct 26 18:48 (116.21.60.xx) This is `whoami` 's output: $ whoami pyh -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Parsing Bounced Emails
Matthew Whipple wrote: http://www.epigroove.com/posts/69/review_of_bbounce_stay_away_far_away ... It this an example of a bounce response that you're having problems parsing? No it's just some other people discussing how they've had the same experience as me with bbounce.com, it sounds good but when you subscribe you don't get anything except $10 less in your pocket. Cheers, Nigel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
On 10/26/07, Beginner [EMAIL PROTECTED] wrote: -bash-3.00$ who am i dpaikkos pts/14 Oct 26 12:16 (host.mydomain.com) Work for me on a bash shell as does whoami. No. You're actually executing the `who` command,which just take the `am i` as its arguments. The results are the same: $ who am i pyh pts/0Oct 26 18:48 (116.21.60.xx) $ who pyh pts/0Oct 26 18:48 (116.21.60.xx) This is `whoami` 's output: $ whoami pyh -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Parsing Bounced Emails
Tom Phoenix wrote: Mail::DeliveryStatus::BounceParser... it doesn't work Maybe you need to fix that module so that it works for you, or to use a different module, or even to write parsing code from scratch. If you can't find a more suitable module for your needs, you could try Parse::RecDescent. Hi Tom, Thanks for this, I've decided to write it from scratch, and could do with some help! The explanation of Parse::RecDescent at: http://search.cpan.org/dist/Parse-RecDescent/lib/Parse/RecDescent.pm Doesn't make sense to me, I don't understand the language but I'm sure with a little work I'll get it. Can you recommend an article/tutorial that will give me a simpler introduction to the concepts of parsing? I can write regexes and have been working on parsing the bounces with them but I think I could do better using parsing techniques and modules that I don't understand right now. I've extracted the content-type and subject from the email headers and am about to start working on getting the rejected email address. Here's what I have so far... foreach my $message_id ( @$messages ) { my $message = join ( '', @{$receiver-message( $message_id )} ); my $message_data = {}; ( $message_data-{header}, $message_data-{body} ) = $message =~ /^ (.+?) (?: (?:\015\012\015\012|\015\015|\012\012) (.+) |) $/sx or main::error ( 'Failed to parse message.' ); ( $message_data-{content_type} ) = $message_data-{header} =~ /^ ( Content-Type:.+ (?: (?: (?:\015\012|\015|\012) \s+.+ ) |) ) $/imx; ( $message_data-{subject} ) = $message_data-{header} =~ /^ ( Subject:.* ) $/imx; } Good luck with it! Thanks :) Cheers, Nigel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
$ who --help Usage: who [OPTION]... [ FILE | ARG1 ARG2 ] ... -monly hostname and user associated with stdin ... If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual. `who am i` is the same as writing `who -m` $ whoami --help .. Same as id -un. Why not just use `whoami`? It gives you exactly what you want. On 10/26/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: my $usr=`who am i`; $usr=~ m{(.+)\s$}; print $usr\n; The 'm' means match. It is searching the string (eg irfanpts/5 Oct 26 09:59 (127.0.0.1:S.1)) for some text followed by whitespace then an endline. The some text gets stored in $1. You probably want: $usr=~ m/^([^\s]+)\s/; $usr = $1; This will search for: begin line, (some text that does not have whitespace in it), whitespace. The bracketed text gets stored in $1. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
Sayed, Irfan (Irfan) wrote: Jeff Pang wrote: You're actually executing the `who` command,which just take the `am i` as its arguments. The results are the same: $ who am i pyh pts/0Oct 26 18:48 (116.21.60.xx) $ who pyh pts/0Oct 26 18:48 (116.21.60.xx) This is `whoami` 's output: $ whoami pyh Thanks for replying to this mail. Now I need to write a regular expression so that I only get username from the output of this command. So I have written like this. my $usr=`who am i`; What's the point with asking questions here if you don't listen to the answers? chomp( my $usr = `whoami` ); $usr=~ m{(.+)\s$}; What did you expect that to do? You apparently need to go back to the docs before trying to use regular expressions. perldoc perlrequick perldoc perlreref perldoc perlretut perldoc perlre perldoc perlop (the latter describes the s/// and m// operators) -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Absolute noobie question regarding opening files on Windows platform
On Oct 25, 9:38 pm, [EMAIL PROTECTED] (mAyur) wrote: On Oct 23, 6:55 pm, [EMAIL PROTECTED] (Paul Lalli) wrote: On Oct 22, 3:27 pm, [EMAIL PROTECTED] (Ayesha) wrote: Hi all I wrote this code to read a file (in the same directory as the script) on Win XP *** #!/usr/local/bin/perl use strict; use warnings; open(READFILE1,./Sample_text_file.txt) or die (Cannot open the given file); [snip unrelated stuff] Not relevant to the problem at hand, but you should also be using lexical filehandles instead of global barewords, and get into the habbit of using the three-argument form of open: open my $READFILE1, '', './Sample_text_file.txt' or die Cannot open the given file: $!; Some suggestions: 1. Instead of using $! for displaying error messages, use $^E. U will get more descriptive error messages. 2. Quickly going thru this digest i observerd usage of '\' in double quotes, this is not recommended. always escape '\' in double quotes like this \\. Heres an example where things can go wrong, lets say ur file/directory name starts with 'n' and u say somthing like open FILE, .\newFile; \n is interpreted as special character by perl or for that matter any other language. Correct way would be open FILE, .\\newFile; ~emptee. Your #2 suggestion is not the best in this case/example. Why did you use a forward slash instead of backslash for the path separator? Better advise would be to: 1) Use double quotes (or the qq() operator) only when needed i.e., when you need variable interpolation. 2) Use the 3 arg form of open as Paul showed. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
On 10/26/07, Jeff Pang [EMAIL PROTECTED] wrote: On 10/26/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Hi All, I am executing my $usr=qx(who am i); to get the user id on unix machine but it is giving error. sh: who am i: not found Oops,it's `whoami` not `who am i` unless you have aliased it. The who command (with arguments am and i) first appeared in Version 1 of ATT UNIX. It is part of POSIX and SUS. The OP problem is the quotes around the command that is causing the shell to try to find a file named who am i (i.e. with spaces in the name of the file). The proper syntax is my $usr = qx(who am i); qx// is not a function; it is a quoting operator. What goes inside it should not be quoted unless you want the shell to see it quoted. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: error in qx
Sayed, Irfan (Irfan) [EMAIL PROTECTED] writes: Hi All, I am executing my $usr=qx(who am i); to get the user id on unix machine but it is giving error. sh: who am i: not found Please guide how to resolve this The problem is that you are trying to run the command who am i (with spaces), if you try that on the commandline you should get the same error. $ who am i Just remove the quotes: my $usr = qx(who am i); And it should work. But..., as allways with perl, TIMTOWTDI. You can get the user id without having to run external programs. See the variables $ and $ in 'perldoc perlvar', and if you need the username, not just the numeric user-id just use getpwuid to look it up. my $user = getpwuid $; -- Christer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Finding time difference from two strings
Wijaya Edward wrote: Hi, Suppose I have this two strings: my $beginning = 'Fri Oct 25 17:37:58 2007'; my $end = 'Fri Oct 26 06:54:09 2007'; How can I compute the time difference between them (in secs)? Is there any CPAN module that does that? I have a large text files which contain two columns (begin + end) which I need to find the time difference between them Date::Manip will do what you need. I've removed the 'Fri' from the start of your dates as only one of them is a Friday; but if your actual data is correct in this regard then the format will be fine as it is. HTH, Rob use strict; use warnings; use Date::Manip; our $TZ = 'GMT'; my $beginning = 'Oct 25 17:37:58 2007'; my $end = 'Oct 26 06:54:09 2007'; my $diff = DateCalc($beginning, $end); print $diff, \n; print Delta_Format($diff, 0, '%sh seconds'), \n; **OUTPUT** +0:0:0:0:13:16:11 47771 seconds -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Finding time difference from two strings
Hi, Suppose I have this two strings: my $beginning = 'Fri Oct 25 17:37:58 2007'; my $end = 'Fri Oct 26 06:54:09 2007'; How can I compute the time difference between them (in secs)? Is there any CPAN module that does that? I have a large text files which contain two columns (begin + end) which I need to find the time difference between them -- Edward Institute For Infocomm Research - Disclaimer -This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: packing a C structure
On 10/26/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi,, iam new to perl..i would like to pack a C structure to send it via socket this is my C structure typedef struct buffer_t { uint32_t a; char b[16]; uint32_t c; uint32_t d; char e[6]; char f[8]; } buffer_t; can u provide a guideline for the format in the Pack command that i need to use... snip Short answer: You cant do this, find a better way to send the data (I would suggest XML, YAML, or JSON). Long answer: You may be able to do this, but only for a given C compiler and OS combination. ANSI C does not specify how structures are laid out in memory, only how the language access it. Some architectures use all sorts of padding to make accessing elements faster (this is why you have to say sizeof(struct foo) to get the size of the structure instead of just calculating it from the elements). You are also not guaranteed what order the elements will be in. The elements themselves may not even be of a given size since char, int, and long only have minimum size definitions. Yet another hurdle is big endian vs little endian memory layout. So, the upshot is you need to find out exactly how the structure is laid out in memory. After you know that, you can choose the proper pack string, but be prepared for it to change. It is better to send the data in a platform neutral manner and reconstitute it on the other end. XML is popular for some reason, but there are many different data transport formats. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Finding time difference from two strings
Wijaya Edward wrote: Hi, Suppose I have this two strings: my $beginning = 'Fri Oct 25 17:37:58 2007'; my $end = 'Fri Oct 26 06:54:09 2007'; How can I compute the time difference between them (in secs)? Is there any CPAN module that does that? I have a large text files which contain two columns (begin + end) which I need to find the time difference between them Date::Manip will do what you need. I've removed the 'Fri' from the start of your dates as only one of them is a Friday; but if your actual data is correct in this regard then the format will be fine as it is. HTH, Rob use strict; use warnings; use Date::Manip; my $beginning = 'Oct 25 17:37:58 2007'; my $end = 'Oct 26 06:54:09 2007'; my $diff = DateCalc($beginning, $end); print $diff, \n; print Delta_Format($diff, 0, '%sh seconds'), \n; **OUTPUT** +0:0:0:0:13:16:11 47771 seconds -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split based on n number of occurances of a character
On Oct 26, 3:51 am, [EMAIL PROTECTED] (Jeff Pang) wrote: using a regex is may suitable. $ perl -e '$x= a;b;c;d;e;f;g;h;@re=$x=~/(\w+;\w+);{0,1}/g;print @re' a;b c;d e;f g;h On 10/26/07, Mahurshi Akilla [EMAIL PROTECTED] wrote: Is there an easy way (without writing our own proc) to split a string based on number of occurances of a character ? for example: $my_string = a;b;c;d;e;f;g;h @regsplitarray = split (/;/, $my_string) splits based on every 1 occurance of ; what if i want it to do 2 at a time ? e.g. $regsplitarray[0] = a;b .. $regsplitarray[1] = c;d .. and so on.. In this example, I used 2.. It could be n in general. Is there a way to do this without writing our own procedure ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/- Hide quoted text - - Show quoted text - Great. This does what I want when I tested it on the command line. Could you explain me the code, starting from @re= ? Thanks.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: New to PerlNET
Are you sure you want a .Net DLL? Looks to me like you need a COM DLL instead. How do you try to register it? Via regsvr32? If yes then you most definitely need a COM DLL. And need to look at PerlCtrl, not PerlNET. Jenda = [EMAIL PROTECTED] ===http://Jenda.Krynicky.cz= When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery I thought that Perl Ctrl was for active X controls. I found and example that looks like what I need in the samples for Perl.NET that's why I went with it. I'm really not sure what I want. I know that I would like to access my Perl package like a DLL library from Excel. ie make a call to the DLL from VBA. The only way I know how to do this is to register the DLL so that I can reference it in my code. Is there another way to do this? I'm all ears. If I can't do it that way, I was thinking about using the VS.net to compile the perl. I know that this is technically possible but have no experience with it. Is this a better way to go? Or should I just rewrite it C#? thanks for the help! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split based on n number of occurances of a character
@re = $x=~/(\w+;\w+);{0,1}/g; Array @re holds the resulting matches (inside the brackets) of the RegEx $x=~/(\w+;\w+);{0,1}/g $x=~/(\w+;\w+);{0,1}/g the /g means don't stop after one match. /(\w+;\w+);{0,1}/ \w is a word This matches one or more word(s) followed by a semicolon, again one or more words, the 0 or 1 semicolons - the greater of the two, I suppose; this allows you to not end in a semicolon. I suspect the {0,1} would have the same affect as ? HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble with Perl Standalone Executable
Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: Trouble with Perl Standalone Executable
On 10/26/07, Yoyoyo Yoyoyoyo [EMAIL PROTECTED] wrote: Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? Are you trying to run the OS X executable you created with pp on XP? The executables are not portable between operating systems (the par files can be if they don't contain XS based modules). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split based on n number of occurances of a character
On 10/26/07, yitzle [EMAIL PROTECTED] wrote: @re = $x=~/(\w+;\w+);{0,1}/g; Array @re holds the resulting matches (inside the brackets) of the RegEx $x=~/(\w+;\w+);{0,1}/g $x=~/(\w+;\w+);{0,1}/g the /g means don't stop after one match. /(\w+;\w+);{0,1}/ \w is a word This matches one or more word(s) followed by a semicolon, again one or more words, the 0 or 1 semicolons - the greater of the two, I suppose; this allows you to not end in a semicolon. I suspect the {0,1} would have the same affect as ? \w matches a word character as Perl defines them (alphanumeric and the underbar character), \w+ matches one or more of them. Perl's definition may not match yours (e.g. can't isn't a word because the single quote/apostrophe character is neither alphanumeric nor an underbar). from perldoc perlre A \w matches a single alphanumeric character (an alphabetic character, or a decimal digit) or _, not a whole word. Use \w+ to match a string of Perl- identifier characters (which isn't the same as matching an English word). If use locale is in effect, the list of alphabetic characters generated by \w is taken from the current locale. See perllocale. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Perl Standalone Executable
Oh, I thought that they might be portable between OSs. My bad. Chas. Owens [EMAIL PROTECTED] wrote: On 10/26/07, Yoyoyo Yoyoyoyo wrote: Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? Are you trying to run the OS X executable you created with pp on XP? The executables are not portable between operating systems (the par files can be if they don't contain XS based modules). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: Trouble with Perl Standalone Executable
On 10/26/07, Yoyoyo Yoyoyoyo [EMAIL PROTECTED] wrote: Oh, I thought that they might be portable between OSs. My bad. PAR files can be: http://search.cpan.org/~smueller/PAR-0.976/lib/PAR/Tutorial.pod#Cross-platform_Packages But the binaries created by pp can't: http://search.cpan.org/~smueller/PAR-0.976/lib/PAR/FAQ.pod#On_what_platforms_can_I_run_PAR?_On_what_platforms_will_the_resulting_executable_run? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: New to PerlNET
On 26 Oct 2007 at 17:15, [EMAIL PROTECTED] wrote: Are you sure you want a .Net DLL? Looks to me like you need a COM DLL instead. How do you try to register it? Via regsvr32? If yes then you most definitely need a COM DLL. And need to look at PerlCtrl, not PerlNET. Jenda I thought that Perl Ctrl was for active X controls. I found and example that looks like what I need in the samples for Perl.NET that's why I went with it. Well, the nomenclature is a bit confused due to Microsoft renaming their stuff a few times. If by ActiveX controls you mean the things included in web pages in place of Java applets then the answer is, no it's not. I'm really not sure what I want. I know that I would like to access my Perl package like a DLL library from Excel. ie make a call to the DLL from VBA. The only way I know how to do this is to register the DLL so that I can reference it in my code. Is there another way to do this? I'm all ears. How do you register it? What version of Excel? Unless it's a very very new version (2007?) I do believe you do need a COM DLL and thus PerlCtrl, not PerlNET. Could you show me a snippet of VBA that uses such a registered object? If I can't do it that way, I was thinking about using the VS.net to compile the perl. I know that this is technically possible but have no experience with it. Well, it is (or at least was) possible to install something into VS.net to be able to do that. That something was made by ActiveState and included PerlNET. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Calling C++ function using Perl
Hi, I am testing some APIs written in C++. Now I am trying to do automation in Perl. Just wondering is there any way I can call C++ APIs using Perl. Thanks a lot in advance for your reply, Bilashi
Re: Calling C++ function using Perl
On 10/26/07, Bilashi Sahu [EMAIL PROTECTED] wrote: snip Now I am trying to do automation in Perl. Just wondering is there any way I can call C++ APIs using Perl. snip You have two options: Inline::CPP* and XS*. Inline::CPP is probably easier to setup, but XS is more robust. * see http://search.cpan.org/~neilw/Inline-CPP-0.25/lib/Inline/CPP.pod ** see the following perldocs: perlxstut, perlxs, perlapi, and perlguts -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split based on n number of occurances of a character
- Original Message - From: Jeff Pang [EMAIL PROTECTED] Newsgroups: perl.beginners To: Mahurshi Akilla [EMAIL PROTECTED] Cc: beginners@perl.org Sent: Friday, October 26, 2007 6:51 AM Subject: Re: split based on n number of occurances of a character On 10/26/07, Mahurshi Akilla [EMAIL PROTECTED] wrote: Is there an easy way (without writing our own proc) to split a string based on number of occurances of a character ? for example: $my_string = a;b;c;d;e;f;g;h @regsplitarray = split (/;/, $my_string) splits based on every 1 occurance of ; what if i want it to do 2 at a time ? e.g. $regsplitarray[0] = a;b .. $regsplitarray[1] = c;d .. and so on.. In this example, I used 2.. It could be n in general. Is there a way to do this without writing our own procedure ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ using a regex is may suitable. $ perl -e '$x= a;b;c;d;e;f;g;h;@re=$x=~/(\w+;\w+);{0,1}/g;print @re' a;b c;d e;f g;h The regexpr that Jeff provided will work if there is an even amount of items, but not if the number of items is odd. The regular expression would miss the 'i' at the end of the string (below). my $my_string = a;b;c;d;e;f;g;h;i; my @re= $my_string =~/(\w+;\w+);{0,1}/g; print join \n, @re; a;b c;d e;f g;h To capture the lone 'i' at the end of the string, you would need a regexpr like this: my @pairs = $my_string =~ /(\w+(?:;\w+){0,1})/g; print join \n, @pairs; a;b c;d e;f g;h i The regular expression above can be explained as: * one or more word chars, \w+ * plus 0 or 1 groups of a semicolon plus one or more word chars: (?:;\w+){0,1} * the second parenthesis group, (?:...), just groups the second group and doesn't capture, but instead, is a group to apply the 0 or 1, {0,1}, quantifier to. The ?: notation says don't capture. * the overall group, including the first set of word chars, is captured between the first left parens, '(', and the final right parens, ')'. Also, to capture groups of 3, for example, you would only need to change the quantifier from {0,1} to {0,2}. my @threes= $my_string =~ /(\w+(?:;\w+){0,2})/g; print join \n, @threes; a;b;c d;e;f g;h;i (From perldoc perlrequick) \w is a word character (alphanumeric or _) and represents: [0-9a-zA-Z_] Mahurshi, you may want to read the manual sections to understand regexps. At the command line type: perldoc perlrequick perldoc perlretut Hope this helps, Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split based on n number of occurances of a character
Mahurshi Akilla wrote: Is there an easy way (without writing our own proc) to split a string based on number of occurances of a character ? for example: $my_string = a;b;c;d;e;f;g;h @regsplitarray = split (/;/, $my_string) splits based on every 1 occurance of ; what if i want it to do 2 at a time ? e.g. $regsplitarray[0] = a;b .. $regsplitarray[1] = c;d .. and so on.. In this example, I used 2.. It could be n in general. Is there a way to do this without writing our own procedure ? I think I would split them into single items and then pair them up again. The program below shows the technique. HTH, Rob use strict; use warnings; my $my_string = a;b;c;d;e;f;g;h; my @regsplitarray; { my @data = split /;/, $my_string; while (@data) { push @regsplitarray, join ';', splice @data, 0, 2; } } print $_\n foreach @regsplitarray; **OUTPUT** a;b c;d e;f g;h -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
help on ip addr
Hello, I want to do the things below: a) get all binded IPs on a redhat linux os.there are maybe more than one IP,like eth0,eth1,eth0:1 etc. b) for each IP,I need to know if it's a private network address (like 192.168.0.1) or a public network address. for the first problem I can read something from /etc/sysconfig/network-script/ifcfg-eth*, or code with @ips = `/sbin/ifconfig` and use regex to capture the IPs.But I don't think these are the best ways. I don't like to use any CPAN module,b/c I'm not admin user,don't have privileges to install those modules. Can you show me a good way? Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/