Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Intsalling perl 5.10 on centos 6.6
2 direct replies — Read more / Contribute
by yaklichk0719
on Jul 23, 2018 at 11:48
    Can somebody please recommend a source of Perl 5.8 or 5.10 to install on CentOS 6.6 apart from the command: yum install Perl? I know that it is OS pre-installed but I need a second version of Perl. Thank you, Sergey
regex and substrings
2 direct replies — Read more / Contribute
by ovedpo15
on Jul 23, 2018 at 10:32
    Hey guys, I'm trying to think of a basic regex which checks if a string is a substring of another string but they are not equal.
    Example:
    my $str1 = "helloworld"; my $str2 = "hello"; my $str3 = "hello";

    So the regex should return true for `$str2 =~ $str1` because $str2 is substring of $str1, but it should return false for `$str2 =~ $str3` because they are the same. Which regex should I use?
Trying to use old source code
7 direct replies — Read more / Contribute
by Radude
on Jul 23, 2018 at 08:55

    Newbie here. I got my hands on some old source code I'd like to use and judging from my research it may be too old to just use. I may have to rewrite everything. Am I correct in thinking this? Here's the beginning of the code...

    #!/usr/bin/perl require 5.005; BEGIN { $| = 1; } use strict; use bytes; #open (EL, '>>rocklog.txt') || die "Can't open rocklog.txt: $!\n"; sel +ect(EL); $|=1; require('r2inter.pl'); use webinter; use IO::Socket; use IO::Select; use Data::Dumper; use Benchmark;
Comparing two files line by line and exporting the differences from the first file
4 direct replies — Read more / Contribute
by jzelkowsz
on Jul 22, 2018 at 20:49

    I have two files. One is an HR record of the user's values; the other is a network export of their attributes. I am trying to compare the two files and find the differences attribute by attribute. The sole reliable key is the samaccountname which is present and consistent in every record. I am trying to produce a file like this:

    barsu991,title,Director of Cooks zingk072,symphonyemployeetype,IKP zingk072,employeenumber,zingk072 zingk072,manager,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
    Where each line of the produced file holds the samaccountname,attribute that is incorrect, and the correct value of the attribute from the HR record. One mistake per line.

    I have tried to do this with loops like below but the best I get is a comparison with the last line and not all of them.

    open(HR, "<hr.txt") || die "can't open hr"; open(AD, "<ad.txt") || die "can't open ad"; open(COMMAND, ">com.txt") || die "can't open com.txt"; while(<HR>) { ($samaccountnameHR,$givennameHR,$snHR,$initialsHR, $employeenumberHR,$symphonyemployeetypeHR,$mailHR, $titleHR,$departmentHR,$companyHR,$lHR, $physicaldeliveryofficeHR,$streetaddressHR,$stHR, $postalcodeHR,$telephonenumberHR,$managerHR)=split(/,$/); while(<AD>) { ($samaccountnameAD,$givennameAD,$snAD,$initialsAD,$employeenumberAD, $symphonyemployeetypeAD,$mailAD, $titleAD,$departmentAD,$companyAD, $lAD,$physicaldeliveryofficeAD,$streetaddressAD,$stAD,$postalcodeAD, $telephonenumberAD,$managerAD)=split(/,$/); if ($employeenumberHR != $employeenumberAD) { print "$samaccountnameHR $samaccountnameAD\n"; } } }
    HR Data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, Uttiam.Barski@pulse.org,Director of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Lreblemet,Walker,J,20178941,IKP, Lreblemet.Walker@pulse.org,Head Cook,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Sovyetk,Karsten,Y,20146598,IKP,Sovyetk.Karsten@pulse.org, Dishwasher,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kovon,Zingerman,K,20113578,IKP,Kovon.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" peizs194,Synthia,Smite,B,20134743,IKP,Synthia.Peizer@pulse.org, Broiler Man,Day Kitchen,MILIFO,Alpena, Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yello,Hutchinson,W,20145712,IKP, Yello Hutchinson,@pulse.org, Bottle Washer,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Haserkrilk,L,20125471,IKP, Zebediah.Haserkrilk@kit.org, Purchaser,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
    AD data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, William.Barski@pulse.org,Chief of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Larry,Walker,J,,IKP,Larry.Walker@pulse.org, Cook,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Steven,Karsten,Y,20146598,IKP, Steven.Karsten@pulse.org,Dishw,Day Kitchen,MILIFO, Alpena,Sully's Kitchen,48720 Belcard,IL,34567,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kevin,Zingerman,K,,,Kevin.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, peizs194,Samantha,Smith,B,20134743,IKP, Samantha.Smith@pulse.org,"Man, Broiler",Day Kitchen, MILIFO,Alpena,Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yaren,Hutchinson,W,20145712,IKP, Yaren Hutchinson,@pulse.org,Bottle Washer,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Hasermann,L,,IKP, Zebediah.Haserman@pulse.org,Purchaser,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"

sub_job in jjobs
2 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 20:29
    Hi Monks :) I always keep thank for monks's nice idae. Do you know jjobs command? Below code, there are jjobs command show me in linux screen. If you know about below command or jjobs, Do you have nice idea to cath JOBID finished? When job finished, JOBID is deleted. Of course I can cath JOBID for every seconds to detact finished JOBID. but that way is not nice I think.. Do monks have nice idea? or special function to catch that JOBID?
    JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME + SUBMIT_TIME APPLICATION 9874211 dideod RUN gui linux test *vevue.il" Jun 2 +7 10:17 test 5507578 dideod RUN gui linux test *vevue.il" Jul +6 11:12 test
Multiple assignment in Perl
1 direct reply — Read more / Contribute
by rnaeye
on Jul 22, 2018 at 19:27

    In Python I can do the following:

    a, b = 0, 1 while b < 50: print(a, b) a, b = b, a + b

    That is shorter version of the following assignment (I think they call it atomic version):

    old_a = a a = b b = old_a + b

    How do I do the first assignment in Perl? My Perl version is

    use warnings; use 5.18.2; my ($a, $b) = (0, 1); while ($b < 50) { say "$a $b"; my $old_a = $a; $a = $b; $b = $old_a + $b; }

    Thank you.

AIX harddisk sum of storage
3 direct replies — Read more / Contribute
by pjzero@90
on Jul 22, 2018 at 13:21

    Hi perl monks, I'm trying to go through 250 aix lpars and capture. I SSH into each host and attempting to run a for loop within backticks, come to find out this does not work, it fails when it gets to "do" Any ideas or workarouns? Thanks.

    sub aixstorage { my $all_servers = 'path to my AIX list of servers'; my @hosts=`cat $all_servers`; my $filename = '/tmp/aixstorage_report.rtf'; foreach my $one (@hosts){ chomp $one; my $ping = `ping -c 1 -w 1 $one 1>/dev/null 2>&1`; if (defined ($ping)) { my $SSH ="/usr/bin/ssh -o ConnectTimeout=3 -o Stri +ctHostKeyChecking=no"; my $space = $SSH root\@$one for i in lspv | awk '{pri +nt \$1}'; do bootinfo -s \$i; done | awk '{sum+=\$1}END{print (sum\/1 +024)}'}'"`; print "$space\n"; }else { print "\nATTENTION: $one is offline\n" } } }
When did perl change /bin wrappers?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 22, 2018 at 07:48
    /usr/bin/corelist used to be a wrapper for (example) /usr/bin/corelist5.18 but now the wrapper is the numbered program itself. When did that change? Thank you
how to stop command
2 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 05:51
    Hi monks. I wonder how to stop command and keep operating script??. I have many files that I want to search for 5 seconds. Below script,I use alarm but I can not keep my script because of die. If I erase die there is no reason to use alarm.. right? please help me
    my $timeout = 5; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my @file_list = `ls user/test/`; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't } # I want to keep go scrip after stop alarm my $file; my @file_list; foreach $file(@file_list){ print "$file\n"; }
option control in script
3 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 00:52
    Hi monks. I wonder that Can script control option by itself?? For example, when I want to use @F(automatic split line by line) , I operate option -ane "perl -ane script.pl". also there are many options such as -n -e ... Recently I write some script to open text file and really useful on @F. but I always forgot option -ane :(.. I know I am not man.. So I need your help. When I operate script "perl script.pl" then script is operated on "-ane" to use @F. Thank you :)

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2018-07-23 16:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (472 votes). Check out past polls.

      Notices?