socket client, can't print w/o newline
first off, i apologize if i'm not describing this as succinctly as possible. i'm working on some client/server stuff using sockets, and i grabbed some code from the net that i don't totally understand. i'm passing packed messages back and forth over a socket from the client/server. Right now i have 2 way communication, the server sends a intro message, the client prints the message, then the client waits for input from the user, sends this info to the server, and then the server acts accordingly, based on what it recieved from the client. Thats all well and good, however: I can't figure out how to get anything to print to the clients stdout/monitor on the line accepting input. while the client is waiting for input from the user, i would like it to display a prompt, like: input:+space+what the user types goes here here is the client being run, i am unsuccessfully trying to print input at the beginning of the 10 and 13 lines, which were user input: [EMAIL PROTECTED]:~/l$ ./int_cli_w_IOSOCK.pl x.x.edu 12000 [Connected to x.x.edu:12215] Welcome to ./serv_p_forking.pl; type help for command list. 10 input score: 100 13 score: 169 here's the client code, the server code follows, though i can't see how the problem would be in the server: # # # # # #!/usr/bin/perl -w use strict; use IO::Socket; my ($host, $port, $kidpid, $handle, $line); my $input = intput ; unless (@ARGV == 2) { die usage: $0 host port } ($host, $port) = @ARGV; # create a tcp connection to the specified host and port #$handle = IO::Socket::INET-new(Proto = udp, $handle = IO::Socket::INET-new(Proto = tcp, PeerAddr = $host, PeerPort = $port) or die can't connect to port $port on $host: $!; $handle-autoflush(1); # so output gets there right away print STDERR [Connected to $host:$port]\n; # split the program into two processes, identical twins die can't fork: $! unless defined($kidpid = fork()); # the if{} block runs only in the parent process if ($kidpid) { # copy the socket to standard output #while (defined ($line = $handle)) { #print STDOUT $line; #} my $byte; my $byte2; my $byte3; my $bytecount = 0; #get initial message from server #which is 59 bytes sysread($handle, $byte, 59); $byte3 = unpack (a*, $byte); print $byte3.\n input ; #do{ #sysread($handle, $byte, 1); #$byte2 .= $byte; #chomp $byte; #print $byte; #}while($byte ne \n); while(sysread($handle, $byte, 4)) { if($byte2 = unpack (i,$byte)){ print score: .$byte2.\n; } } kill(TERM, $kidpid); # send SIGTERM to child } # the else{} block runs only in the child process else { # copy standard input to the socket while (defined ($line = STDIN)) { print $handle $line; } } # # # # # # here's the server code: # # # # # # # #!/usr/bin/perl use Chatbot::Eliza; use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr use POSIX 'WNOHANG'; use constant PORT = 12000; use strict; $|=1; my $hostinfo; my $client; my $quit = 0; #signal handler for child die events $SIG{CHLD} = sub { while ( waitpid(-1,WNOHANG)0 ) { } }; #signal handler for interrupt key and TERM signal $SIG{INT} = sub { $quit++ }; my $listen_socket = IO::Socket::INET-new(LocalPort = PORT, Listen= 20, Proto = 'tcp', Reuse = 1, Timeout = 60*60, ); die Can't create a listening socket: $@ unless $listen_socket; warn Server ready. Waiting for connections. . .\n; while (!$quit) { next unless $client = $listen_socket-accept; $client-autoflush(1); defined (my $child = fork()) or die Can't fork $!; if ($child == 0) { $listen_socket-close; interact($client); exit 0; } $client-close; } #} sub interact { my $welcome = Welcome to $0; type help for command list.; my $pkd_welcome = pack(a*, Welcome to $0; type help for command list.); my $lgth = length($pkd_welcome); print \nl - $lgth\n\n; $client-send($pkd_welcome); $hostinfo = gethostbyaddr($client-peeraddr); printf [Connect from %s]\n, $hostinfo-name || $client-peerhost; #$client-send(Command?); #$client-send(pack(i,42*42)) ; while ( $client) { next unless /\S/; # blank line if (/10/i){ $client-send(pack(i,10*10)) ; print recv'd - 10\n; } elsif (/13/i){ $client-send(pack(i,13*13)) ; print recv'd - 13\n; } elsif (/29/i ){
perl default variable question
hi, i'm using a perl script i found to change the names of batches of files. The program works as is but it's giving me a weird warning. I'm familiar with $_, but not $_[3]. Can someone explain what $_[3] is, and how i can get this script to stop throwning the warning? Thanks, Ryan i found the file here: http://noisybox.net/computers/eren/ file download link: http://noisybox.net/computers/eren/eren.pl warning thrown: Use of uninitialized value in pattern match (m//) at C:\pPerl\eren.pl line 82. (i changed the file a bit so it won't be the same line number if you checkout the whole file) code from my file: 76 foreach my $file (@files){ 77 next if -d($root . $file); 78 79 next if (($preview) and not ($file =~ /$filefilter/)); 80 @_ = split /\//, $replacestr; 81 my $icase = ''; 82 ($_[3] =~ /i/) and $icase = 'i'; #** 83 my $cmd = sprintf(\$file =~ /%s/%s;, $_[1], $icase); 84 85 next if not eval $cmd; 86 87 $preview and print PREVIEW: ; 88 $matchct++; 89 90 my $oldfile = $file; 91 print $oldfile -- ; 92 $file =~ eval \$file =~ s$replacestr;; 93 print $file\n; 94 $preview and next; 95 rename($root . $oldfile, $root . $file) or print Failed to rename $root$oldfile\n; 96 } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl default variable question
On 9/18/07, Ryan Moszynski [EMAIL PROTECTED] wrote: thanks, so i can just test to see if $_[3] exists and it kills the warning. On 9/18/07, Andrew Curry [EMAIL PROTECTED] wrote: @_ is the list of incoming parameters to a sub. So if you write a sub, you refer to the first parameter in it as $_[0], the second parameter as $_[1] and so on. And you can refer to $_# as the index number of the last parameter: -Original Message- From: Ryan Moszynski [mailto:[EMAIL PROTECTED] Sent: 18 September 2007 15:12 To: beginners@perl.org Subject: perl default variable question hi, i'm using a perl script i found to change the names of batches of files. The program works as is but it's giving me a weird warning. I'm familiar with $_, but not $_[3]. Can someone explain what $_[3] is, and how i can get this script to stop throwning the warning? Thanks, Ryan i found the file here: http://noisybox.net/computers/eren/ file download link: http://noisybox.net/computers/eren/eren.pl warning thrown: Use of uninitialized value in pattern match (m//) at C:\pPerl\eren.pl line 82. (i changed the file a bit so it won't be the same line number if you checkout the whole file) code from my file: 76 foreach my $file (@files){ 77 next if -d($root . $file); 78 79 next if (($preview) and not ($file =~ /$filefilter/)); 80 @_ = split /\//, $replacestr; 81 my $icase = ''; 82 ($_[3] =~ /i/) and $icase = 'i'; #** 83 my $cmd = sprintf(\$file =~ /%s/%s;, $_[1], $icase); 84 85 next if not eval $cmd; 86 87 $preview and print PREVIEW: ; 88 $matchct++; 89 90 my $oldfile = $file; 91 print $oldfile -- ; 92 $file =~ eval \$file =~ s$replacestr;; 93 print $file\n; 94 $preview and next; 95 rename($root . $oldfile, $root . $file) or print Failed to rename $root$oldfile\n; 96 } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
saving system output as $
is there a way to save the output of a system call as a variable to print later and suppress the initial printing of the output of the call to the terminal?? ### my $keepStat; $keepStat = system stat $inputScratch; ## I DONT WANT THIS TO PRINT # AS SOON AS IT'S PERFORMED print .. $keepStat . ..\n; ## I DO WANT IT TO PRINT NOW ## '0' is printed, instead of the 'stat' output ### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
passing a list as a variable
Is there a way to make my commented 'foreach line act the same as the line above it? Can I pass a list as a variable as I am trying to do, or doesn't perl support that? ### #!/usr/bin/perl -w $|=1; #use strict; system clear; my @array = 1024; my $list4 = 0..10,33..43,100..111; foreach (0..10,33..43,100..111){ #foreach ($list4){ $array[$_] = $_; print array--$array[$_]-- --$_--\n; } ### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: passing a list as a variable
thanks, that works, but it won't solve my problem. I'm writing a program where the user enters a list through the keyboard, like: 0..10,33..43,100..111 I would like to pass this list directly into a foreach function. The problem is, when i pass my scalar in, i get: ### Argument 0..15,33..43,100..111 isn't numeric in array element ### i guess a better question is, can I ?cast? that string into a variable that can be recognized by the foreach? On 7/24/06, Joshua Colson [EMAIL PROTECTED] wrote: On Mon, 2006-07-24 at 12:40 -0400, Ryan Moszynski wrote: Is there a way to make my commented 'foreach line act the same as the line above it? Sure. Can I pass a list as a variable as I am trying to do, or doesn't perl support that? ### #!/usr/bin/perl -w $|=1; #use strict; system clear; my @array = 1024; # In the previous statement, you're initializing a 1024 # who's values are all undefined # my $list4 = 0..10,33..43,100..111; # use an array instead of a scalar my @list4 = ( 0..10, 33..43, 100..111 ); #foreach (0..10,33..43,100..111){ #foreach ($list4){ foreach (@list4) { $array[$_] = $_; # this next statement is going to print a bunch of nothing # useful as there are no values in the array print array--$array[$_]-- --$_--\n; } ### HTH -- Joshua Colson [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: passing a list as a variable
thanks guys. Dr. Ruud's solution does the trick. I was trying to get around having to do that, but i guess you can't have everything. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
awesome help, but, a question
Mumia, thanks for your work on answering my help request. I really appreciate it. However, while your solution works perfectly in your sample program, since I am new to perl, I am having trouble understanding some of the techniques you used, and i am having trouble integrating the solution that you came up with into my own program. how do i get all of this inside my if statement? I don't understand why the second line works(I know its comparing the values for greater/lesser, but not how in the world perl is interpreting it, if i'm making any sense) what are the ':'s doing?, and lastly, what is eg? i know you spent too much time on this already, but i'd really appreciate you clearing this up for me. this stuff isn't in my perl book. . . $str =~ s/(?:(\d+)-(\d+)|(\d+));?/ $3 ? '' : ($2 $1 ? '' : 'y') /eg; '' eq $str; my program ## foreach ($temp2 = ) { $list1 = $temp2; if ($list1 =~ /regex/){ print yay\n; }else {print boo\n;}; ## Mumias solution: ## our ($datastr, @F); my @data = \('1-10;25;33;100-250', '1-10;25;33;x100-250', '1-10;25;33;100-250-90', '1-10;25;33-9-18;100-250', '1-10;25;33-18;100-250'); my @checkranges; push @checkranges, sub { # F1: Okay my $str = shift; $str =~ s/(\d+-\d+|\d+);?//g; '' eq $str; }; push @checkranges, sub { # F2: Buggy my $str = shift; $str =~ m/^((\d+-\d+|\d+);?)+$/g; }; push @checkranges, sub { # F3: Okay my $str = shift; $str =~ m/^((\d+-\d+|\d+)(;|$))+$/g; }; push @checkranges, sub { # F4: Okay, the best; it checks ranges. my $str = shift; $str =~ s/(?:(\d+)-(\d+)|(\d+));?/ $3 ? '' : ($2 $1 ? '' : 'y') /eg; '' eq $str; }; my $truefalse = sub { shift() ? 'true' : 'false'; }; $~ = 'FUNFORMAT'; $datastr = \'STRING'; @F = qw(FUNC-1 FUNC-2 FUNC-3 FUNC-4); write; for $datastr (@data) { @F = (); push @F, $truefalse-($_-($$datastr)) for (@checkranges); write; } format FUNFORMAT = @@ @ @@ $$datastr,$F[0], $F[1], $F[2], $F[3] . __END__ Output: STRINGFUNC-1 FUNC-2 FUNC-3 FUNC-4 1-10;25;33;100-250true true true true 1-10;25;33;x100-250 falsefalsefalsefalse 1-10;25;33;100-250-90 falsetrue falsefalse 1-10;25;33-9-18;100-25falsefalsefalsefalse 1-10;25;33-18;100-250 true true true false -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
regex repetition
I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: ### foreach ($temp2 = ) { $list1 = $temp2; if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) { print yay\n; }else {print boo\n;}; #print ...,$list1, ...\n; } ### which doesn't work, because as soon as it matches the first time, anything goes. How do i get it check for repetition, even though i don't know how many repetitions there will be. there could be 1,2,3,5, even 10 groupings. so the pattern isns't hard, there has to be a number, then either a '-' or s ';', then repeat or not. the only special case is the first one which could just be a single number, or a number '-'number. I just don't know how to implement it. (#(-||;))(#(-||;))(#(-||;)) thanks, ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: beginners Digest 6 Jul 2006 08:41:28 -0000 Issue 2890
rob, thanks, awesome help. I've been stuck on that part for too long. i'm replying to the questions in your reply, but your solution worked, so you can ignore this if youre busy. -- Forwarded message -- From: Rob Dixon [EMAIL PROTECTED] To: beginners@perl.org Date: Thu, 06 Jul 2006 00:03:27 +0100 Subject: Re: iterate over newlines Ryan Moszynski wrote: Hi Ryan this is a snippet of a file i'm trying to process: ### iotests ( WriteEmUp [create:openwr:write:close] ReadEmUp [openrd:read:close] ) i need my perl regex to recognize iotests, then make anything that matches .[.] into a string. I can't count on the whitespace or the new lines being there or not. i read the file into perl with: I'm not sure what you mean here. Are you talking in terms of the regex '.' character? My best guess is that you want to find everything that looks like word [stuff] but please let me know. yes, thats what i meant. I should have been more clear. # open (YIP, /home/ryan/code/perl/enzo_fio_tests/output/verify_4MB/ fio_enzo_verify_4mbb.inputscratch) || die(No SOUP FOR YOU!!); You should put $! in your die string so that you can see the reason the open failed. right again LINE: while (YIP){ and i've been struggling with some form of this, which doesn't work, though I'm not quite sure why: if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){ A regex will test $_ by default, so this could be if ( /iotests/ || /\[/ || /\]/ ){ next LINE if /./gs; I don't understand what this is supposed to do. The regex will succeed unless $_ contains the empty string, which can never be true within this while loop. i forgot the * i wanted this code: if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){ next LINE if /./gs; unless ( $` =~ /\)/ ) { to find 'iotests' or '[' or ']', and then if ANYTHING, including the empty string, go to the next line unless it found a ')' in the line above, to make sure that the text inside the parentheses is proccessed, even if it was in the same line as the closing paren. thats why i commented that other line. i didn't right in the code to process the lines between iotests and the right parenthese yet. unless ( $` =~ /\)/ ) { #get # of pes Again, I can't see what you are trying to do. $` holds the contents of the object string preceding the last successful pattern match. Do you mean $_ again? #unless ( $_ =~ /\)/ ){ Like this, except you've commented it out. $blah4 = $blah4 . $_ ; print $blah4.\n; } ### right now, as you can see, i'm just trying to turn the chunk i need into a multiline string so i can work on it, but i haven't been successfull. I know I must be approaching this the wrong way, any ideas? This looks like an ideal case for the range operator '..'. Read about it in perldoc perlop. that was my big problem, i didn't know about '..' i've been searching through all sorts of documentation and hadn't run across it until you suggested it. In the following code, the test /iotests/ .. /\)/ will be false until a line is found which contains 'iotests'. It will then stay true until a line arrives containing ')'. While this is true the current line is appended to $chunk. If the test is false then $chunk holds the full block to be processed (because of the chomp() it is a single line of text). The code I have written prints out the chunk, and also finds all the data I think you want from this string and prints that out as well. The chunk is then undefined so it doesn't get processed again. The output from your very small data set is shown. If it's not quite what you want then let us know. my $chunk; while (YIP) { chomp; if ( /iotests/ .. /\)/ ) { # Inside a chunk? $chunk .= $_; } elsif (defined $chunk) { print $chunk, \n\n; while ($chunk =~ /(\S+\s*\[.*?\])/g) { print $1, \n; } print \n\n\n; undef $chunk; } } ** OUTPUT iotests (WriteEmUp [create:openwr:write:close]ReadEmUp [openrd:read:close] ) WriteEmUp [create:openwr:write:close] ReadEmUp [openrd:read:close] I hope this helps, Rob also, you code worked just about exactly as is in my program, though i changed a few details. Once again, awesome, thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: iterate over newlines
sorry for the resend, i made a mistake in the subject line and didn't want anyone folling the thread to miss the resolution. -- Forwarded message -- From: Ryan Moszynski [EMAIL PROTECTED] Date: Jul 6, 2006 1:57 PM Subject: Re: beginners Digest 6 Jul 2006 08:41:28 - Issue 2890 To: [EMAIL PROTECTED], beginners@perl.org rob, thanks, awesome help. I've been stuck on that part for too long. i'm replying to the questions in your reply, but your solution worked, so you can ignore this if youre busy. -- Forwarded message -- From: Rob Dixon [EMAIL PROTECTED] To: beginners@perl.org Date: Thu, 06 Jul 2006 00:03:27 +0100 Subject: Re: iterate over newlines Ryan Moszynski wrote: Hi Ryan this is a snippet of a file i'm trying to process: ### iotests ( WriteEmUp [create:openwr:write:close] ReadEmUp [openrd:read:close] ) i need my perl regex to recognize iotests, then make anything that matches .[.] into a string. I can't count on the whitespace or the new lines being there or not. i read the file into perl with: I'm not sure what you mean here. Are you talking in terms of the regex '.' character? My best guess is that you want to find everything that looks like word [stuff] but please let me know. yes, thats what i meant. I should have been more clear. # open (YIP, /home/ryan/code/perl/enzo_fio_tests/output/verify_4MB/ fio_enzo_verify_4mbb.inputscratch) || die(No SOUP FOR YOU!!); You should put $! in your die string so that you can see the reason the open failed. right again LINE: while (YIP){ and i've been struggling with some form of this, which doesn't work, though I'm not quite sure why: if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){ A regex will test $_ by default, so this could be if ( /iotests/ || /\[/ || /\]/ ){ next LINE if /./gs; I don't understand what this is supposed to do. The regex will succeed unless $_ contains the empty string, which can never be true within this while loop. i forgot the * i wanted this code: if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){ next LINE if /./gs; unless ( $` =~ /\)/ ) { to find 'iotests' or '[' or ']', and then if ANYTHING, including the empty string, go to the next line unless it found a ')' in the line above, to make sure that the text inside the parentheses is proccessed, even if it was in the same line as the closing paren. thats why i commented that other line. i didn't right in the code to process the lines between iotests and the right parenthese yet. unless ( $` =~ /\)/ ) { #get # of pes Again, I can't see what you are trying to do. $` holds the contents of the object string preceding the last successful pattern match. Do you mean $_ again? #unless ( $_ =~ /\)/ ){ Like this, except you've commented it out. $blah4 = $blah4 . $_ ; print $blah4.\n; } ### right now, as you can see, i'm just trying to turn the chunk i need into a multiline string so i can work on it, but i haven't been successfull. I know I must be approaching this the wrong way, any ideas? This looks like an ideal case for the range operator '..'. Read about it in perldoc perlop. that was my big problem, i didn't know about '..' i've been searching through all sorts of documentation and hadn't run across it until you suggested it. In the following code, the test /iotests/ .. /\)/ will be false until a line is found which contains 'iotests'. It will then stay true until a line arrives containing ')'. While this is true the current line is appended to $chunk. If the test is false then $chunk holds the full block to be processed (because of the chomp() it is a single line of text). The code I have written prints out the chunk, and also finds all the data I think you want from this string and prints that out as well. The chunk is then undefined so it doesn't get processed again. The output from your very small data set is shown. If it's not quite what you want then let us know. my $chunk; while (YIP) { chomp; if ( /iotests/ .. /\)/ ) { # Inside a chunk? $chunk .= $_; } elsif (defined $chunk) { print $chunk, \n\n; while ($chunk =~ /(\S+\s*\[.*?\])/g) { print $1, \n; } print \n\n\n; undef $chunk; } } ** OUTPUT iotests (WriteEmUp [create:openwr:write:close]ReadEmUp [openrd:read:close] ) WriteEmUp [create:openwr:write:close] ReadEmUp [openrd:read:close] I hope this helps, Rob also, you code worked just about exactly as is in my program, though i changed a few details. Once again, awesome, thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org
processing a hash of a hash of a hash
I am trying to print out a hash of a hash of a hash table(with code chunk 1), but I keep getting the following error: Use of uninitialized value in hash element at ./clearwhite.pl line 522. I don't understand where this error is coming from since I can process a hash of a hash just fine, using code chunk2, and i know that the values I am trying to process exist, as i can print them out, or run the exists/defined/true tests on them as i do here. Where is my mistake? How is this done? thanks fo rlooking at this, ryan - 1 - Use of uninitialized value in hash element at ./clearwhite.pl line 522. ## print Exists\n if exists $top{$getgroup}{IOTESTS}{0} ; print Defined\n if defined $top{$getgroup}{IOTESTS}{0}; print True\n if $top{$getgroup}{IOTESTS}{0}; #prints Exists\nDefined\nTrue\n foreach $key (keys %top){ foreach $key1 (keys %{$top{$key}}){ foreach $key2 (keys %{$top{$key{$key1}}}){ # line 522 print $key $key1 $key2 $top{$key}{$key1}{$key2}\n; } } } ## 2 - works # my $key; my $key1; my $key2; my $value; foreach $key (keys %top){ foreach $key1 (keys %{$top{$key}}){ print $key $key1 $top{$key}{$key1}\n; } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
iterate over newlines
this is a snippet of a file i'm trying to process: ### iotests ( WriteEmUp [create:openwr:write:close] ReadEmUp [openrd:read:close] ) i need my perl regex to recognize iotests, then make anything that matches .[.] into a string. I can't count on the whitespace or the new lines being there or not. i read the file into perl with: # open (YIP, /home/ryan/code/perl/enzo_fio_tests/output/verify_4MB/fio_enzo_verify_4mbb.inputscratch) || die(No SOUP FOR YOU!!); LINE: while (YIP){ and i've been struggling with some form of this, which doesn't work, though I'm not quite sure why: if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){ next LINE if /./gs; unless ( $` =~ /\)/ ) { #get # of pes #unless ( $_ =~ /\)/ ){ $blah4 = $blah4 . $_ ; print $blah4.\n; } ### right now, as you can see, i'm just trying to turn the chunk i need into a multiline string so i can work on it, but i haven't been successfull. I know I must be approaching this the wrong way, any ideas? thanks ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: iterate over newlines
i really hope thats overkill for my problem. I have my program finshed, this is the last condition i have to deal with. Also, my supervisor would prefer me not to use any nonstandard modules. On 7/5/06, Tom Phoenix [EMAIL PROTECTED] wrote: On 7/5/06, Ryan Moszynski [EMAIL PROTECTED] wrote: i need my perl regex to recognize iotests, then make anything that matches .[.] into a string. I can't count on the whitespace or the new lines being there or not. This sounds like a job for Parse::RecDescent, maybe? http://search.cpan.org/~dconway/Parse-RecDescent-1.94/ Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
reg ex problem
i have this string extracted from a text file i'm writing a program to process: test_freq = 1.0001; and i have to extract the 1.0001 i can't count on the whitspace being where it now is. I would like to change this line of perl $getTestFRQ =~ s/\D+//g; so that instead of killing all non digit characters, it will kill all non digit characters except for the period. How do i do this? thanks, ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg ex problem
thanks for the help, that did the trick On 6/27/06, Ryan Moszynski [EMAIL PROTECTED] wrote: i have this string extracted from a text file i'm writing a program to process: test_freq = 1.0001; and i have to extract the 1.0001 i can't count on the whitspace being where it now is. I would like to change this line of perl $getTestFRQ =~ s/\D+//g; so that instead of killing all non digit characters, it will kill all non digit characters except for the period. How do i do this? thanks, ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response