- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 8
- Posts with Upvotes
- 7
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
15 Posted Topics
Re: you can try testing $A and $B (not the best variable name choices, btw) for being numerical, try the guide here: [URL="http://perldoc.perl.org/perlfaq4.html#How-do-I-determine-whether-a-scalar-is-a-number/whole/integer/float%3F"]How do I determine whether a scalar is a number/whole/integer/float?[/URL] Apart from that, there's no need to push to @_, in fact, it's probably a very bad idea. Assigning … | |
Re: The simplest way to handle this is as follows: 1. [URL="http://perldoc.perl.org/functions/readdir.html"]opendir/readdir[/URL] the logs folder, save the file paths to @log_files 2. foreach @log_files, [URL="http://perldoc.perl.org/functions/open.html"]open file[/URL], then search it for the pattern 3. if found, [URL="http://perldoc.perl.org/functions/push.html"]push file path[/URL] to @found_patterns 4. then, search file for 2nd pattern, push to @found_patterns2 on … | |
Re: localtime and gmtime are not modules, these are built-in perl functions, same as time. | |
Re: The threads->new() method (actually threads->create()) accepts a "coderef" which is a reference to a method, and a list of parameters that are passed to the coderef: [CODE]threads->new(\&thread_job, $key, $device_ip{$key}, $index)[/CODE] if you use () after the coderef then perl will a: invoke the method, then b: return a reference to … | |
Re: You need to check the return value of the function: [CODE]if (is_success(getstore("http://www.example.com/", "/tmp/store/file")))...[/CODE] Check [URL="http://search.cpan.org/perldoc/LWP::Simple"]LWP::Simple CPAN page[/URL] for a more thorough explanation. You may also wand to look at [URL="http://search.cpan.org/perldoc/LWP::UserAgent"]LWP::UserAgent[/URL] and [URL="http://search.cpan.org/perldoc/HTTP::Response"]HTTP::Response[/URL] The file in $url is stored at wherever you point $file to. | |
Re: use [URL="http://perldoc.perl.org/functions/localtime.html"]localtime[/URL]: [CODE] ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); ... $wday is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday. [/CODE] So basically you need [code](localtime(time))[6][/code] | |
Re: The bulk of this job can be pulled with a simple file iteration [CODE] open my $FH, '<', $filepath || die "Cannot open file $filepath - $!"; my (@completed, @not_completed); while (<$FH>) { chomp; my @status = split /\|/; if ($status[1] =~ /Completed/i) { push @completed, \@status; } else { … | |
Re: [QUOTE=boshu;1457276]Hi all, Create a new file (test.new) and parsed all the test.hrh contents there. While parsin I checked whether the flag exists, if not then added the whole string like "#define FLAG". If it was defined and everthing is right then doing nothing. Else change the status from "undef FLAG" … | |
Re: There are many such tools (as with everything in Perl). The exact nature of the tool(s) recommended needs to be based on the exact nature of the problem. For instance, to test simple http request/response you can try [URL="http://search.cpan.org/~szbalint/WWW-Curl-4.15/lib/WWW/Curl.pm"]WWW:Curl[/URL] which is a Perl-binding for the [URL="http://curl.haxx.se/"]cUrl[/URL] tool. OTOH, if you … | |
Re: Storable serialise data to binary, that is, it stores the perl representation of the data-structure/object in a file, referred to as an "image". That file can only be used by another Perl program that uses Storable to read and use the data. Therefore, there is no need for an extension … | |
Re: That's a rather messy way, I'd suggest a simpler route: [CODE] use strict; use warnings; open(my $INI, '<', "reg.txt") or die "cant open the file $!"; #always use three param open, and assign to a variable. my %results; while (<$INI>) { #more idiomatic #don't parenthasise (capture) what you don't need … | |
Re: This one liner is equivalent to [CODE] my ($r, @output); open (my $FH, '<', 'file.txt') || die "cannot open file.txt for input - $!"; #Add text after <\/module-data> (second condition) #but only if it came after <process-type="Remote"> (first condition) while (<$FH>) { #each line is assigned to $_ chomp; if … | |
Re: print "@array" will print all the elements of the array, delimited by the value of $" (default is space). If there are more than 1 element, you can format an array into a string by assigning $": [CODE]my @array = qw(123 234 345 456); local $" = ', '; print … | |
Re: Hi, ColMatrix, I've looked in the CPAN documentation, and your code seems to be in order, So, as mentioned above, it is most likely a matter of the field you assign to $VarComparison being empty, and therefore $VarComparison being empty as well. To verify that, add a [CODE]print "**$VarComparison**\n"[/CODE] line … | |
Re: [QUOTE=j111c222;1439885]Hi, I have encounter a strange result couldn't figured out. [CODE]# Str with format "Mon MM HH", try to skip leading space in DD. my $str = "Jan 8 11"; # Jan, 8th 11 o'clock print substr($Str, 0,3) . substr($Str, 4,2)=~s/^\s+//. substr($Str, 7,2) . "\n"; [/CODE] The result is "Jan11", … |
The End.