Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

The Monastery Gates

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

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Is this a severe error?
7 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 03, 2015 at 10:39
    Hi Monks, I get this error in my code:
    Use of uninitialized value in concatenation (.) or string in line 1245

    The snippet of code is the following:
    for (my $s=$start_of_barrel_region; $s<=(($start_of_barrel_region+$len +gth_of_barrel_region)); $s++) { my $aa_pos=$s+1; print PLP_FILE "$aa_pos\t".$split_query_for_PLP[$s]."\t".$hash_p +lp_lbl_barrel_region_only{$s}."\n"; }

    The erroneous line seems to be :
    my $aa_pos=$s+1;
    The program executes without problem, I am just wondering why I get this error and how I can fix it...
    Thank you in advance
Perl file rename
5 direct replies — Read more / Contribute
by keltan
on Jun 02, 2015 at 19:22

    HI

    I've got problem i need to write file renamer. I know that there are topics on this forum with answers but i need to write slightly different code and i hope you will help. Yes this is my homework but i dont need direct answers i appreciate tips.
    !/usr/bin/perl -w use strict; my $dirname; $dirname = 'D:\test'; my $test = $ARGV[0]; my $test1 = $ARGV[1]; my $pattern = qr/$test/; my $pattern1 = qr/$test1/; opendir(DIR, $dirname) or die "Can't opendir $dirname: $!"; while ( defined (my $file = readdir DIR) ) { next if $file =~ /^\.\.?$/; my $new = $file; $new =~ s/$pattern/$pattern1/; rename($file,$new) }
    What i need to write is a script which after this command: ./rename *.pl "s/^/old_/" will add to all files with extension .pl prefix old_ I've been trying few approaches but all failed. Funny thing is that in other languages i don't have that problem only PERL always beat me down.
scp output without having to use "Net::SCP" in Perl
4 direct replies — Read more / Contribute
by pjzero@90
on Jun 02, 2015 at 17:13
    Question, I'm trying to scp output/file from one machine to another without using Net::SCP, any ideas? Example:
    #system("/usr/bin/tmp",$output,"$USER\@$host:/tmp/LOGS/");
    While trying to do this in a for loop:
    my @OUTPUT = `ls -ltr /tmp` foreach my $output (@OUTPUT) { chomp ($output); system("scp $output user@server:/tmp/LOGS"); } scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2 scp: illegal option -- w usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file +] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2
    No luck.....
XML Parse
4 direct replies — Read more / Contribute
by tfeitor
on Jun 02, 2015 at 13:07
    Hi everyone, I'm new with Perl and tried to parse the following xml file. I try thing's like libXML and other thing's, but I couldn't get values like code_a / name. Can someone Help me with this. Thanks in Advance Tiago
    <?xml version="1.0"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envel +ope/"> <soapenv:Body> <dlwmin:getBookById xmlns:dlwmin="http://www.test.com/integration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <result xmlns="http://www.test.com/integration/integration"> <status> <state>0</state> </status> <books> <num>12345</num> <book> <code_a>11111</code_a> <name>Come to the Dark Side 1st Ed</name> <otherVal>ABC</otherVal> <otherVal2>1999</otherVal2> </book> <book> <code_a>22222</code_a> <name>Come to the Dark Side 2nd Ed</name> <otherVal>ABC</otherVal> <otherVal2>2001</otherVal2> </book> <Title>Come to the Dark Side</Title> <typeOfBook>SciFi</typeOfBook> <writer>Darth Vader</writer> </books> </result> </dlwmin:getBookById> </soapenv:Body> </soapenv:Envelope>
    Like I said before I'm new with perl :) 4 hours, I need to parse a lot of files in a Production Env, I tried the code bellow:
    use strict; use warnings; use XML::LibXML; use XML::LibXML qw( ); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('out.xml'); for my $result ($doc->findnodes('/books/book')) { for my $interv ($result->findnodes('book')) { my $bk = $interv->find('code_a'); my $bk_name = $interv->find('name'); print("$bk - $bk_name"); } }
    and this one (I couldn't understand how to interate with the hash):
    use strict; use XML::Simple; use Data::Dumper; my $doc = XMLin('out.xml'); print Dumper($doc);
    antoher thing the xml was in one line. thanks
why does location of function matter?
6 direct replies — Read more / Contribute
by smartyollie
on Jun 01, 2015 at 17:54
    I have run into a situation several times at my current job where the location of a perl function affects whether it works or not. I've never had this happen before and feel like I'm missing something obvious. The current scenario happens on both Windows (Strawberry Perl) and UNIX (Solaris v5.8.4). I have a function called PostValidate with one argument. When I put the function definition AFTER the main body of code, it runs; when I put the function before, it fails with

    Too many arguments for main::PostValidate at y.pl line 349, near "$ofile)"

    The call within the main body looks like this:

    if ($validate) {
    PostValidate($ofile);
    }

    I don't have any prototypes defined and I'm really at a loss as to why it should matter where the function is. Any ideas?
Serial communication between perl and arduino
5 direct replies — Read more / Contribute
by perl_sck_58
on Jun 01, 2015 at 11:32

    Hi Monks, I am trying to setup a serial communication between arduino uno and pc using Perl. I am using Win32::SerialPort module for the same

    The problem is I am not able to read or write to the arduino In config.pl file I am saving the settings to conf.cfg file and in serial.pl I am trying to write to arduino

    Config.pl

    use strict; use Win32::SerialPort; my $ob = Win32::SerialPort->new ('COM22') || die; $ob->baudrate(9600); $ob->parity("none"); $ob->parity_enable(1); # for any parity except "none" $ob->databits(8); $ob->stopbits(1); $ob->handshake('none'); $ob->buffers(4096, 4096); $ob->write_settings || die "cant write settings"; $ob->save("conf.cfg"); print "wrote configuration file conf.cfg\n";

    Serial.pl

    use strict; use Win32::SerialPort 0.11; my $ob = Win32::SerialPort->start ("conf.cfg") || die; $ob->write("abc"); $ob->write("xyz"); undef $ob;

    After running this code I get a message that "Second Write attempted before First is done at Simple_serial_com.pl line 10. Use of uninitialized value $written in numeric ne (!=) at C:/Perl64/site/lib/Win 32/SerialPort.pm line 1580."

    In the arduino program I am just waiting to receive for any serial data

    void setup() { pinMode(13,OUTPUT); Serial.begin(9600); } void loop() { if(Serial.available()) { pinMode(13,HIGH); } }

    I also tried adding a delay between the two serial writes in the perl program, but also got the same error message.

    Please let me know if I need to do any other configurations or if I am doing something wrong

    Thanks all

    I found where the issue is, 64 bit build of perl is the culprit, I installed 32 bit build and it started working

XML Simple
4 direct replies — Read more / Contribute
by Arenas
on May 31, 2015 at 08:03

    I start with perl now. I don't no how to do.

    (I comms from Powershell, sorry)

    Please,

    ----------

    script:

    #!C:/Dwimperl/perl/bin/perl.exe use strict; use warnings; use LWP::UserAgent; my $url = 'http://athome.myminicity.com/xml'; my $ua = LWP::UserAgent->new(); my $response = $ua->get($url); if($response->is_success) { # print $response->decoded_content; my $city = XML::Simple->new; print $city->{city}->{population} print population ? print bases =>tra ? } else { die $response->status_line; }

    The module xml::simple is not load

    How format numbers (1246633 => 1 246 633)

    Thanks

    @r

WCF alternative in Perl
1 direct reply — Read more / Contribute
by Divan
on May 30, 2015 at 22:12

    I'm a primarilly a .NET/js/DB developer but I know a little bit of Perl (learned the basics as my first programming language).

    I've just recieved a small project in Perl 5.10+ and that sparkled my interest in Perl again. I've decided to master it alongside with Linux (debian based) which I use ocasianlly.

    I've assembled a reading list of, what should be, the best books on Perl.

    Now, I'm interested in service oriented programming, SOA, and since I have experience with WCF, I'm looking for something "similar" in Perl.

    I was looking at Kensho::Task and saw POE and IO::Async for async programming. I also saw Mojolicious, Dancer, Catalyst and now I'm wondering where to start, what is preffered in the community etc.(I know that these things have different purposes)

    Should I first learn the low level stuff (fork, socket programming) and then middlewares, before diving into high level stuff or just start at the top ?

    Thanks in advance.

get each column key/value
2 direct replies — Read more / Contribute
by Peamasii
on May 30, 2015 at 10:38
    Hello, I have been trying to figure out how to do this with DBI. I have a few tables each containing different fieldnames and just one row of values. I'd like to write a sub which stores the column name and corresponding value in row, in a hash, in the order they are in. The I want to loop over the hash and retrieve the key/value pairs. How can I do this? I looked at at fetchrow_hashref and fetchrow_arrayref but the columns were not returned in order. Any help would be appreciated. Update: I found the answer
    sub print_stats { my($table) = @_; my $sth = $dbh->prepare('SELECT * FROM '.$table) or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute # Execute the query or die "Couldn't execute statement: " . $sth->errstr; my $names = $sth->{NAME}; # or NAME_lc or NAME_uc while( my $report_row = $sth->fetchrow_arrayref() ) { for my $col_idx ( 0 .. $#{$names} ) { print "$names->[$col_idx]: $report_row->[$col_idx]\n"; } } }
decimal to binary conversion
3 direct replies — Read more / Contribute
by mp0065789
on May 30, 2015 at 07:10

    Can anyone help here:

    #!/usr/bin/perl -w use strict; use warnings; print "Enter decimal number less than 256:"; my $decimal; $decimal=<STDIN>; #chomp $decimal; print $decimal & 128 <=> 0; print $decimal & 64 <=> 0; print $decimal & 32 <=> 0; print $decimal & 16 <=> 0; print $decimal & 8 <=> 0; print $decimal & 4 <=> 0; print $decimal & 2 <=> 0; print $decimal & 1 <=> 0 ;
    output: F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:255 11111111 F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:12 00000000 F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:8 00000000

    output is coming wrong for all except 255. Frown

tie variable
2 direct replies — Read more / Contribute
by grasshopper!!!
on May 29, 2015 at 17:31

    Is it possible to tie a scalar to Tk entry and a subroutine as to return length of input on each letter input. Writting twitter client and wish to display number of characters input to entry in label on each keystroke at a loss. thank you

what are my options with perl, sybase dblib?
1 direct reply — Read more / Contribute
by taiq_m
on May 29, 2015 at 15:42
    i am on solaris 10 using sybase dblib on most of my perl scripts. we are now moving to RHEL 6. Pls note I have no root access, can i get sybase dblib to work on rhel? we have DBI on rhel but no dbd sybase. can i have dbd sybase installed on one of my custom libraries? below is what i have. perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
New Meditations
Net::FTP fail workaround
1 direct reply — Read more / Contribute
by kurgan
on Jun 03, 2015 at 07:50

    I ran into an issue where Net::FTP was failing at random while connecting many times over the life of a script. I searched for a solution only to find that others were having similar issues. It seems that this excellent module does not actually check to see if the port that is used for connection is working correctly before forging on. The only way around it (that I have found) was to check for the error and reconnect on-the-fly until a working port has been found. It is not a perfect solution as it takes extra resources that could be used elsewhere if the error check was done at the module level, but it has worked well for me so far.

    I just thought others might find this of some help if they find themselves in the same situation. I was not really sure where to post this, so I asked on the CB and pointed here (thank you all for the help!). If you all find this helpful at all, please share it with others at your pleasure.

New Monk Discussion
Can I please have multiple downvotes per (certain monk's) posts.
14 direct replies — Read more / Contribute
by BrowserUk
on May 29, 2015 at 10:30

    I'd willing give up 5 XP per downvote to do it. 10 even.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
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 meditating upon the Monastery: (21)
As of 2015-06-03 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?















    Results (139 votes), past polls