Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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
Can anyone tell me what is going on with my code?(Regex match variables)
3 direct replies — Read more / Contribute
by samh785
on Sep 30, 2015 at 13:40
    My code:
    if ($macs[1] =~ /(\S{17})\|(\S{17})/) { print "$macs[0] MAC1: $1\n"; print "$macs[0] MAC2: $2\n"; $mac1 = $1; $mac1 =~ s/:/-/g; $mac2 = $2; $mac2 =~ s/:/-/g; #line 65 print "Converted Mac1: $mac1 Mac2: $mac2\n"; #line 66 }
    And the output:
    ESO13 MAC1: 00:60:16:5D:4D:B4 ESO13 MAC2: 00:60:16:5D:4D:B5 Use of uninitialized value $mac2 in substitution (s///) at +line 65, <STDIN> line 1. Use of uninitialized value $mac2 in concatenation (.) or string at ipc line 66, <STDIN> Converted Mac1: 00-60-16-5D-4D-B4 Mac2:

    For some reason $2 is uninitialized the second time I try to use it. The same exact code for $1 works. Any ideas why this might be happening? Any help is greatly appreciated!

recursively building a hash of arrays of scalars
3 direct replies — Read more / Contribute
by aral
on Sep 30, 2015 at 12:08

    G'day. I feel terribly stupid today. Been out of touch with my more complicated Perl project for half a year, and now I cannot wrap my brain around hash and array references anymore.

    I want to be able to recursively copy a hash of arrays of scalars (manually, so I can make adjustments on certain nodes). But I fail in creating writeable references to all types (hash, array, scalar) to pass to my recursion routine. A short example with my error looks like this:

    my %testHash; # initialize hash my $hashRef = \%testHash; # get a reference to that # get a reference to an element 'a' inside the hash (that does not +yet exist) my $destref = \${$hashRef->{'a'}}; # <- problematic line # assign a value to the hash element 'a' $destref = "value"; # verify the result print $hashRef->{'a'} . "\n"; # outputs "SCALAR(0xaddress)"

    In essence, I do not even know whether the "problematic line" is able to create a valid reference, because element 'a' does not exist at the time. How do I get a $destref that I could also pass to a function, and when modifying it's value, accomplish a change of $hashRef->{'a'}?

    Thanks in advance for any help. I have done this before and can't get my head around my own code at the moment. I hope I am making sense :/

Can Multiple perl versions coexist without effecting one another on Solaris?
1 direct reply — Read more / Contribute
by newperlmonkey
on Sep 30, 2015 at 11:33

    I have the below scenario on Solaris 10 (both QA and Prod) in which I'm confused as to take which route and seeking help from monks here.

    1) I need to modify one existing perl script say are 15 diff scripts running currently) to do the PGP encryption of the xml file and move to a diff directory for which I'm planning to use Crypt::OpenPGP 1.12 version from CPAN. But during installation this is asking for so many dependent modules to be installed aswell which is becoming so cumbersome and thinking there must a simpler way to do it and reached out here.

    2) The default perl 5.8.4 that comes with solaris 10 is present in '/usr/bin/perl' and is not used by any perl scripts.

    3) Another version of perl 5.10.1 is installed in the location '/tib/esb/Perl/bin' and a symlink is created under '/opt/esb/Perl/bin/perl' (installation is done by a diff user "perluser" and this new path is placed ahead of the default perl path) and this symlink location is referred in the shebag line of the scripts as '#!/opt/esb/Perl/bin/perl' and these scripts are invoked using cron job thru shell script which has invoking command as '/tib/company/bin/'

    4) if we have to upgrade the existing 5.10.1 to 5.20.2 then we have do a thorough testing of rest of the scripts aswell which we are not going to touch and I'm afraid we dont have enough time to test all the scripts. So as a quick fix I'm thinking to install the latest version 5.20.2 in to a separate folder say '/tib/esb/Perl520' and then create a symlink and place it in '/opt/esb/Perl520/bin/perl' and then use in the shebang as '#!/opt/esb/Perl520/bin/perl' of the only one script that I'm planning on changing without effecting the other scripts. Then I wanted to invoke this script from shell command as '/tib/company/bin/' which is the location of this script on server.

    5) Question - By doing this way should I expect any challenges going forward? With my approach would I be able to get what I'm looking for? It would be really helpful if someone can throw light on this.

    FYI - I'm a newbie, so pls dont flame me.
Data manipulation on a file
2 direct replies — Read more / Contribute
by sstruthe
on Sep 30, 2015 at 10:47

    Hi There, this is probably a really easy one for you monks out there. I have the following script, it's using awk for the main manipulation to read into the array a list of linux mount points. I find awk easier on delims than split and regex but thats because I know it.

    #!/usr/bin/perl # use strict; use warnings; my $mounts = `mount | grep 'type nfs' | awk -F/ '{print \$1,\$3}' | so +rt`; print $mounts; mounts now looks like this but I have no idea how I read in the two co +lums into a hash of hosts with array of mountpoints. this is the file coming in but not in full host1 /var/mount1 host1 /var/mount2 host2 /var/mount5 host3 /var/mount3 host3 /usr/mount1

    what I want coming out is

    $mountpointkey=host1:/var/mount1:/var/mount2,host2:/var/mount5,host3:/var/mount3:/var/mount1 hope this makes sense appreciate any effort that comes my way from this many thanks

Meaning of error mesage of regexp.
3 direct replies — Read more / Contribute
by nikolay
on Sep 30, 2015 at 09:41

    What does mean the eval and line indexes i have in error message on my regexp as follows:

    Use of uninitialized value $1 in concatenation (.) or string at (eval 292) line 1.

    Here it is 292 and 1 . -- From which point it is counted? Thank you.

6 direct replies — Read more / Contribute
by A1 Transcendence
on Sep 30, 2015 at 06:49

    Enlightened Monks, I am writing to you today so that your wisdom may flow through me. I am working with a small problem that is a part of a larger string of programs.

    The objective is to write a simple(<10 lines) script that will combine Maternal and Paternal strings into a new string:

    1) Open my Table File, and skip the first line in the table as it is unnecessary for the task.

    2) Read my file that is shown below two lines at a time(i guess). The Lines are IDed Maternal and Paternal strings of 0s and 1s.

    3) Combine the the same ID strings by adding the 0s and 1s creating a new string.

    4) Lastly I want to only keep and store the combined> and labeled strings that have 0s and 2s only, no 1s in the string.


    INDIV 16051347(G-C) 16051497(A-G) 16052239(A-G) 16052513(G-C) 16052618(G-A) 16053659(A-C) 16054667(C-G)

    HG00096.M 0 0 0 1 1 1 1 1 0 0 0 0 0

    HG00096.P 0 0 1 0 0 0 0 1 0 0 0 0 0

    HG00097.M 1 1 0 0 0 0 0 0 0 0 0 1 0

    HG00097.P 0 0 1 0 0 1 0 1 1 1 0 0 0

    HG00099.M 1 1 0 0 0 0 0 0 0 0 0 0 0

    HG00099.P 0 0 0 0 1 1 0 0 1 1 0 1 0

    HG00100.M 0 0 1 1 1 1 1 1 1 1 1 1 1

    HG00100.P 1 1 0 0 0 1 0 0 1 1 0 1 0

    HG00101.M 1 1 0 0 0 1 0 0 1 1 0 1 0

    HG00101.P 0 0 1 1 1 1 1 1 1 1 1 1 0

    HG00102.M 1 1 0 0 0 0 0 0 0 0 0 1 0

    HG00102.P 0 0 1 0 0 1 0 1 1 1 0 1 0


    1 1 1 0 0 1 0 1 1 1 0 1 0


    @add = (); open (TA, "Table_C22-17") || die "Can't open file"; while (<TA>) { $c++; if ($c > 1) {$count++; @a = split /\t/,$_; chop ($a[0]); for $x (0..$#a) { if ($count <= 2) { $add[$x] += $a[$x]; push (@tl, $add[$x]); next; } } } } $count = 0; print "@tl\n";
Premature end of script headers
5 direct replies — Read more / Contribute
by gszabo
on Sep 30, 2015 at 03:04

    I have installed an IPAM system (Gestioip)to my server ( Debian7, apache 2.2 ) it starts with an .sh script, it downloads the modules, copy the files, made config files.
    The script downloads perl modules, and create an apache config. opening it in a browser generates this error in apache.log
    Tue Sep 29 09:44:05 2015 error client Premature end of script headers: index.cgi
    Permissions of files, directories, the perl script is okay, i installed the program in virtual machine succesfuly in similar enviroment.
    How can i debug this error?
    Thanks for your help
Sigils & Nowns?
1 direct reply — Read more / Contribute
by rich.wilder
on Sep 29, 2015 at 23:35

    Hi Monks,

    I'm slowly making my way through "Programming Perl" and today made it to the example on page 19 where I encountered the syntax:

    open(GRADES, ...

    So what is the entity GRADES? I understand it's a user label name where the file handle is returned from open but why isn't there a sigil prefix?



targetting for multiple perl versions
5 direct replies — Read more / Contribute
by bagyi
on Sep 29, 2015 at 21:18

    I'm writing some job control sort of program in perl. Most of the time I use file manipulation (move,copy, file path, file stat), compress/uncompress, file transfer (ftp) and sometimes SOAP, XML.

    The thing is I've written some small program and it is working fine in my development environment (perl 5.22.0). but when I tried to run on different system with perl version 5.8. some modules are not by default installed. :(

    so the question is what is the general strategy in dealing with this kind of thing?

How do you share an object(Telnet Session) between threads?
5 direct replies — Read more / Contribute
by jmlynesjr
on Sep 29, 2015 at 13:43

    How do you share an object(Telnet Session) between threads?

    I need the Telnet session below available to 3 threads(connect, disconnect, & scan). $telnetsession is of type Net::Telnet per print(ref($telnetsession)).

    This is part of a larger wxPerl script. All of the display and interlocking between the GUI and threads seems to working corectly.

    Crossposted to wxperl-users.

    Thanks, James

    # Define the Thread shared data area - All threads access this scaler +data fine my %common : shared; $common{ip} = ""; # Localhost $common{port} = "7356"; # Local Port as defined in gqrx $common{telnetsession} = 0; # Object Pointer ??? Problem ?? +? $common{tnerror} = 0; # Status $common{connect} = 0; # Command $common{connected} = 0; # Status $common{disconnect} = 0; # Command $common{scanstart} = 0; # Command $common{scanstarted} = 0; # Status $common{beginf} = 0; # Scan - Beginning Frequency $common{endf} = 0; # Scan - Ending Frequency $common{step} = 0; # Scan - Frequency Step $common{squelch} = 0; # Scan - Minimum RSSI(Recieved Signal + Strength Indicator) $common{rssi} = 0; # Scan - Latest RSSI $common{pause} = 0; # Scan - Time between scans - msec $common{listen} = 0; # Scan - Time to Listen to a strong si +gnal - msec $common{mode} = 0; # Scan - Demodulator Type $common{stopthreads} = 0; # Command # Connect the Telnet Session - #1 sub Connect { while(1) { if($common{stopthreads}) {print "\nConnect Thread Terminated\n +"; return}; if($common{connect}) { if(!$common{connected}) { print "Open Telnet Connection to gqrx\n"; my $telnetsession = Net::Telnet->new(Timeout => 2, port + => $common{port}, Errmode => sub {$common{tnerro +r} = 1;}); $telnetsession->open($common{ip}); $common{telnetsession} = shared_clone($telnetsession); + # Line 92 Errors $common{connected} = 1; $common{connect} = 0; } } threads->yield(); } }
    Error message: Thread 1 terminated abnormally: Unsupported ref type: GLOB at ./thread line 92 thread 1


    There's never enough time to do it right, but always enough time to do it over...

Add your question
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!
  • 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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (4)
    As of 2015-10-04 21:52 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (105 votes), past polls