Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  • Users: whn
  • Content: Threads
  • Order by date
  1. whn

    How to efficiently implement file comparison

    Let's say I have a baseline file like this: 4.1.27-4.1.2-amd64-1cccde6e81b2c42b cmos2q installed and running lm-sensors2q installed and running lspci2q installed and running mcelog2q installed and running mpt2q not needed pmbus2q installed and running smartmon2q installed and running And a...
  2. whn

    Looking for a way to enhance the implementation

    I have a piece of codes constructing an email sender: sub getSender { my $host = hostname;a # use Sys::Hostname; my $domain = 'xyz.com'; my $char = '.'; my $from; if($host =~ /$domain/) { # hostname() may return a string like foo.bar.xyz.com and in this case # we want to...
  3. whn

    How to assign bit shift to a variable?

    I know this line works: print "OK!! Child($$, $pid) $res ended with ", $? >> 8; print "\n"; But how do I assign the line above into a variable? e.g. $logMsg .= "OK!! Child($$, $pid) $res ended with ", $? >> 8; $logMsg .= "\n"; While compiling it, I got this: Useless use of right bitshift...
  4. whn

    A simple code runs at cmdline, but not in cron job

    A simple code just like this: my $cmd = "gwsh root\@$ip \"uname -r\""; my $ret = `$cmd`; When I ran the code at cmd prompt, it's fine. But when it's run in a cron job, $cmd returns nothing. What did I miss here? Many thanks.
  5. whn

    A very simple script does not work

    Hi Experts, I have a very simple script listed below: #! /usr/bin/perl my $cmd = "ssh root\@198.18.154.133 \"/a/sbin/tcpdump -v -n -i eth0 port 11640 -w /tmp/mytcpdump.pcap 2>/dev/null\" 2>/dev/null &"; system($cmd); my $cmd2 = "/usr/bin/ssh root\@198.18.154.130 \"cd /tmp; ./go_load...
  6. whn

    Failed in installing XML::LibXML

    I am having difficulties in installing XML::LibXML. Below is my system: % cat /etc/issue Ubuntu 14.04.2 LTS \n \l % perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi (with 41 registered patches, see perl -V for more detail) I have...
  7. whn

    Questions about Getopt::Long

    Please take a look at the piece of code below: #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my ($debug, $emailAddr, $fussy, $fussier); GetOptions( # This is line 8 "d" => \$debug, "e=s" => \$emailAddr, "fussy" => \$fussy, "fussier" => \$fussier, ) || die; if($fussy) {...
  8. whn

    Please help me to understand how Dumper() works.

    At first, please take a look at the piece of code: #!/usr/bin/perl use Data::Dumper; my @a1 = ('a','b'); my %h1; for(my $i = 0; $i <= $#a1; $i++) { $h1{$i} = \@a1; } my @a = (\%h1); print Dumper(\@a); exit; A test run: % tt.pl $VAR1 = [ { '1' => [...
  9. whn

    Distinguish x=undef vs x=''

    Sample codes: use Data::Dumper; my %h; $h{a} = undef; $h{b} = ''; $h{c} = 'z'; print Dumper(\%h); # Dumper can distinguish the difference between $h{a} and $h{b} foreach my $k (keys(%h)) { # The following block cannot distinguish the difference between $h{a} and $h{b} if(!$h{$k}) {...
  10. whn

    How to sort an all-digit matrix

    Hi Experts, Assume there is an m by n all-digit matrix: X11 X12 ... X1n X21 X22 ... X2n ... Xmn Xmn ... Xmn I need help to write a method that somewhat like 'order by' in ansi sql. This method shall be able to sort the matrix by ANY number of column indices passed in at cmdline. For example...
  11. whn

    String match issue

    Please take a look at the small sample code here. I just don't understand why it actually finds a match!! #!/usr/bin/perl -w my $str = "group=1,101,102"; my $ip = "1.1.1.1"; if($str =~ /$ip/) { print "The string contains this IP!!\n" } else { print "The string does not contain this...
  12. whn

    Cannot make this simple regexp work

    My brain must be short circuited!! $string = 'trunk.codeanalysis.test'; print "\$string = $string\n"; if ($string = m/trunk\.codeanalysis\.([a-z]+)/) { $suffix = $1; print "Match - #$suffix#\n"; } else { print "No match!!\n"; } exit 0; A test run: % ./test.pl $string =...
  13. whn

    How to run perl code from anywhere

    Hi Experts, Please take a look at a small demo program including file structure below: [VM] perl 25 % pwd /tmp/perl [VM] perl 26 % ls -l * -rwxr-xr-x 1 test staff 133 2013-09-18 12:20 run.pl* lib: total 4 -rw-r--r-- 1 test staff 233 2013-09-18 12:20 utils.pm [VM] perl 27 % cat run.pl...
  14. whn

    how to permanently change @INC

    % perl -V ...... ...... @INC: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl . Is there a way I can recompile perl so that...
  15. whn

    Sort version numbers

    My company has multiple product lines and the version numbers are in different format. For instance, one product line's version numbers may look like this: 5, 5.2, 5.11. The highest version in this example is 5.11. Therefore, we cannot simply sort them numerically. Another product line's...
  16. whn

    How to handle $x = undef and $x = 0

    I wrote a small piece of codes that does not run as I expected: my $x1 = undef; my $x2 = 0; my $x3 = -1; my $x4 = 1; my @arr = ($x1, $x2, $x3, $x4); for(my $i = 0; $i <= $#arr; $i++) { if($arr[$i]) { print "\$i = $i, \$arr[$i] = $arr[$i]\n"; } else { if($arr[$i] == 0) { # This...
  17. whn

    Questions about p4perl...

    I am trying to use p4perl. But I am stuck in step one - to install p4perl. I did a search on this forum and found no threads related to perforce and/or p4perl. Therefore, I'll keep my questions short for now though I may have many follow-up questions later. According a release note at perforce...
  18. whn

    Modification of a read-only value attempted

    I wrote a small piece of codes to test out ReadOnly.pm. use Readonly; Readonly::Hash my %readOnlyHash1 => ( 'key11'=>{ 'key21'=>1, 'key22'=>1, }, 'xyz'=>{ 'abc'=>1, }, ); Readonly::Hash my %readOnlyHash2 => ( 'xyz'=>{ 'abc'=>1, }, ); my $k1 = 'key11'; my $k2 =...
  19. whn

    Construct a hash from a log file.

    A sample log file somewhat look like this: x11:x12:x13:...:x1m:value1 x21:x22:x23:...:x2m:...:x2n:value2 x31:x32:x33:...:x3i:value3 x41:x42:x43:...:x4i:...:x4j:value4 Note that -- 1) In each row, the elements are delimited by ':'; 2) The number of elements in each row may very, i.e. m, n, i...
  20. whn

    Need help in construct an regexp

    I need to find a string match at Microsoft site. Out of its web page, there could be one or more strings look like this: <a class="download" onclick="return false;" href="confirmation.aspx?id=36888"...

Part and Inventory Search

Back
Top