Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
read and write to the same file
2 direct replies — Read more / Contribute
by amy063000
on Mar 06, 2015 at 15:26
    Hello, I am a beginner to perl, really needs some help from here. I have a file as following: id name age 1 amy taylor 20 2 paul li 59 3 Bob hand 30 now i need to add each person's email to the same file. I need to get person's id, go to database to find that person's email and then add the email to that person in the same line. What is the good way to do that? Does anybody have example. Your help is greatly appreciated. thanks, Amy
How can you tell what Perl version was used to compile a module
No replies — Read more | Post response
by johnniestang
on Mar 06, 2015 at 15:06
    I'm testing out a new Linux build and had the Support team install Sybase Open Client for me, which includes Sybase::CTlib. The box has Perl 5.10.1 installed but I'm getting the undefined symbol Perl_Tstack_sp_ptr error message. From the FAQ and https://bugs.archlinux.org/task/9078, I know this error is because the module was compiled with something other than 5.10.1. Recompiling the module would be new for me. So is there a way to determine what Perl version Sybase::CTlib was compiled with?
Tutoring for beginner?
1 direct reply — Read more / Contribute
by Halbird
on Mar 06, 2015 at 14:17
    Hi! I'm looking for someone to give me some advice on a peice of programming I am doing, I'm willing to tip for tutoring (not sure if this is allowed). This is beginner work so nothing demanding, Message me if interested!
Multiple Device Logon execute the same command
3 direct replies — Read more / Contribute
by PerlCramps
on Mar 06, 2015 at 12:36
    My fellow monks; being that I am new to perl. I am asking for help with a perl script that would allow me to logon to multiple devices collecting the device name from a text file. Execute the same command on all devices in list and export collected data into one text file call DeviceResults.txt. This works in the AIX host shell. for server in `cat serverlist`; do printf"20s" $server; ssh -o "BatchMode yes" -q$server oslevel -s; done I am hoping that there is one monk with the help I need. Thanks
Dots appearing when opening a directory
7 direct replies — Read more / Contribute
by The_Last_Monk
on Mar 06, 2015 at 11:49
    Fellow Shaolin monks, So i am trying to print the names of a file in a directory, here is my code:
    $dir = path to the directory opendir (DIR,$dir) or die "dead"; while(my $text = readdir DIR) { print "$file\n" }
    The directory has a text file in it, but once it opens the directory, the output is this:
    . .. File.txt
    What would be a solution to get rid of those dots? Is there a regex that should be used here so that it only prints the files starting with a word or a number? If so, what would be the regex?
alarm in windows, alternative?
1 direct reply — Read more / Contribute
by sniperd
on Mar 06, 2015 at 10:46
    Hello Monks! I need to make a system call in Windows and sometimes it times out and I'm trying to use alarm, however it looks like that doesn't work in windows (Activestate). Here is my code:
    use warnings; use strict; main (); sub main { eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm 2; my $data = `ping 127.0.0.1 -t`; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors } else { print "got here\n"; } }
    To keep it simple I just chucked in there ping -t for testing. The real code is calling phantomjs to hit a website and the .exe just blows up sometimes, basically getting stuck and I the script will just sit there. Is there some simple command I can use to call command line on windows and have it just die (or continue) if a certain number of seconds have passed? Thank you in advance.
[perl6] Complex Attribute Validation and/or Triggers
1 direct reply — Read more / Contribute
by duelafn
on Mar 06, 2015 at 10:03

    Are there ways in perl6 to write more complex attribute validators and/or before/after/around modifiers on attribute access? I can't seem to find anything that would let me, say, implement an interval class with a lower and upper bound, or call some code every time an attribute is changed. Did I miss it somewhere?

    class Interval { has Real $.lb is rw = die 'Lower bound is required'; has Real $.ub is rw = die 'Upper bound is required'; } ### Example which does not work: # class Interval { # has Real $.lb where * <= $.ub is rw = die 'Lower bound is requir +ed'; # has Real $.ub where * >= $.lb is rw = die 'Upper bound is requir +ed'; # after lb { say "Lower bound was changed!" if @_ } # } my $i = Interval.new( lb => 1, ub => 3); say $i.perl; $i.lb = 0; # should print message say $i.perl; $i.lb = 6; # should blow up! say $i.perl;

    Thanks,
        Dean

extract pattern from large blob of text
2 direct replies — Read more / Contribute
by littleperl
on Mar 06, 2015 at 09:34

    I would like to extract the value for 'var nonce' from the following text blob (string)

    "... var realm = "heaven"; var nonce = "186248:541534:a67930c5cffeb25a5485e6b4f32570e2"; var qop = "auth"; var uri = "/earth.lp"; ...."

    Currently my code looks a like:

    my $req = HTTP::Request->new(GET => $server_endpoint); my $resp = $ua->request($req); my $message = $resp->decoded_content; $message =~ m/nonce/i; print " starts: @- \n ends: @+ \n";

    To get the begin and end of the nonce keyword (and next I will need to extract the value (186248:541534:a67930c5cffeb25a5485e6b4f32570e2) ).

    Problem is I do not get the start or end position back on this string? what am I missing here?

numeric hash keys
3 direct replies — Read more / Contribute
by AWallBuilder
on Mar 06, 2015 at 08:38
    Dear all,

    I've done some reading and it sounds like it is possible to have numeric hash keys and perl is supposed to figure out when numbers should act as numbers and when they should act as strings. However, I am getting an error message that indicates to me that it thinks my numbers are strings. Any advice appreciated. Thanks

    use strict; use warnings; use Data::Dumper; ############################ my $inGNPS="MsRtLib_all.tab"; open(IN,$inGNPS); my %HoPMAnnot; my %HoPMrtAnnot; while(my $line=<IN>){ chomp $line; my ($ParMass,$RT,$annot)=split(/\t/,$line); $HoPMAnnot{$ParMass}=$annot; $HoPMrtAnnot{$ParMass}{$RT}=$annot; } close(IN); print Dumper (%HoPMAnnot); ###### my $inATdat="consensus_features_extracted.csv"; open(IN,$inATdat); while(my $line=<IN>){ chomp $line; next if($line =~/^,/); # header starts with comma my ($feat_numb,$mz_min,$mz_max,$rt_min,$rt_max,$quality,$inten +sity)=split(/,/,$line); foreach my $PM (keys %HoPMAnnot){ if ($PM <=$mz_max && $PM >=$mz_min){ print join("\t",$line,$HoPMAnnot{$PM})."\n"; } } } close(IN);

    data dumper output

    $VAR1 = '272.043'; $VAR2 = 'N/A'; $VAR3 = '272.188'; $VAR4 = 'N/A'; $VAR5 = '838.844'; $VAR6 = 'Sodium_Formate'; $VAR7 = '601.393'; $VAR8 = 'N/A';

    error

    Argument "parent mass" isn't numeric in int at checkTheoFeat4GNPSannot.pl line 25, <IN> line 1034.

Export global variables not working correctly
4 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 06, 2015 at 00:45

    I'm not good at English, but I believe that when you look at codes you will understand what I meant

    package AAA; use 5.20.1; use lib ('.'); use BBB; use parent('Exporter'); our @EXPORT=('$b','$msg'); our $bbb=BBB->new(); return 1; package BBB; use 5.20.1; use lib '.'; use AAA; sub new{ my $class=shift; my $self=bless {},$class; return $self; } sub hello{ my $self=shift; say 'hello'; } sub hello2{ my $self=shift; $b->hello(); } return 1; package main; use 5.20.1; use lib ('.'); use AAA; $bbb->hello2();

    $ perl test.pl Global symbol "$bbb" requires explicit package name at test.pl line 5. Execution of test.pl aborted due to compilation errors.


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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (14)
    As of 2015-03-06 21:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:









      Results (177 votes), past polls