Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
How to retrieve the port number on a Multiple TCP Chat Client Server
No replies — Read more | Post response
by thanos1983
on Jul 10, 2014 at 22:00

    Dear Monks,

    On my code every time a new user connects to the server I am binding his port into a hash $hash{$port} = $text[1]; for future reference through the: $new_sock->peerport() process, I pick up the port number.

    The moment that a new client will connect with the server this value will change, as expected, because $new_sock->peerport() is binded with $new_sock = $sock->accept(). The problem that I am having is that I can not find a way to separate the clients when they are communicating with the server.

    Update:

    The goal is to be able to change the name of the client who is sending a message to the server, so I can make a small function to send this message to all clients apart from him self.

    Working sample of Server Code:

    Update the Server code: 3 and Solution with minor problem (It sends the message to all clients, I am trying to fix this sending the message to all clients apart from the one who sends the message.)! Update 2, I added the client code for experimentation purposes:

    I tried to retrieve the socket from two points: my @sockets = $readable_handles->can_write(); or $buf = <$sock>;. Since I this is the first server client that I am creating with the Select function I am not really familiar with it, and I can not find relative information to my problem online.

    Any advice would be much appreciated. Thank you all for your time and effort assisting me with my problem.

    Seeking for Perl wisdom...on the process...not there...yet!
Regex trouble w/ embedded 0s?
2 direct replies — Read more / Contribute
by roboticus
on Jul 10, 2014 at 18:19

    Hello, all:

    I've been fighting this for a little while, and I'm stumped. I'm trying to pull a file apart, and for some reason, my regex works normally most of the time, but sometimes fails and I can't figure out why.

    Here's an example:

    $ cat bug.pl #!/usr/bin/perl use strict; use warnings; my $str = join("", map { chr } 0x13, 0x00, 0x00, 0x00, 0xf8, 0x90, 0xbc, 0xac, 0x3a, 0x26, 0x1c, 0x27, 0xb3, 0x22, 0x22, 0xb3, 0xf6, 0x60, 0x23, 0x2d, 0x77, 0xbf, 0xdb, 0xda, 0xd1, 0xad, 0x0a, 0x98, 0x1a, 0x38, 0xae, 0x76, 0xee, 0x77, 0x66, 0x35, 0x66, 0x00, 0x65, 0x00, 0x74, 0x00, 0x69, 0x00, 0x64, 0x00, 0x5f, 0x00, 0x69, 0x00, 0x73, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x5f, 0x00, 0x32, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x67, 0x00, 0x72, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00, 0x31, 0x00, 0x37, 0x00, 0x0a, 0x00, 0x53, 0x00, 0x69, 0x00, 0x7a, 0x00, 0x65, 0x00, 0x3a, 0x00, 0x20, 0x00, 0x34, 0x00 ); for my $c (split //, $str) { printf "%02x ", ord($c); } print "\n"; if ($str=~/^(.{36})(.*?)\0\0\0/) { print "Found it!\n"; } else { print "?where is it?\n"; } $ perl bug.pl 13 00 00 00 f8 90 bc ac 3a 26 1c 27 b3 22 22 b3 f6 60 23 2d 77 bf db da d1 ad 0a 98 1a 38 ae 76 ee 77 66 35 66 00 65 00 74 00 69 00 64 00 5f 00 69 00 73 00 6c 00 61 00 6e 00 64 00 5f 00 32 00 2e 00 74 00 67 00 72 00 00 00 ff fe 76 00 65 00 72 00 73 00 69 00 6f 00 6e 00 20 00 31 00 37 00 0a 00 53 00 69 00 7a 00 65 00 3a 00 20 00 34 00 ?where is it?

    I expected to see "Found it!", as there's clearly a string of three zeroes on the eighth line. (Note: I manually inserted the line breaks in the output.)

    I'm probably doing something crazy, but I can't see it.

    I don't expect that it matters, but I'm running 5.14.4 (from cygwin).

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Reversing Arabic String direction
6 direct replies — Read more / Contribute
by wael_ahmed
on Jul 10, 2014 at 17:20
    Hi all, I have an Arabic string that contains both letters and digits. The problem is that the string appears reversed, I tried using the reverse function but it reverses both the letters and digits while I need to reverse the letters only. Please help with this issue.
Compress a entire directory
5 direct replies — Read more / Contribute
by kepler
on Jul 10, 2014 at 16:55
    Hi, Does anyone has a clue how to compress in zip or tar format several files in the SAME compressed file? Kind regards, Kepler
accessing elements of reference to hash of arrays
3 direct replies — Read more / Contribute
by johnguillory
on Jul 10, 2014 at 16:28
    Hello, The following code successfully prints all content of a hash of arrays:
    for $x ( keys %HoA ) { print "$x: "; for $i ( 0 .. $#{ $HoA{$x} } ) { print "$HoA{$x}[$i] "; } } Output looks like this: Keys: array 8001: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl 5022: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl 1018: bp ne br no lt lw ni l I pass the %HoA to a function and want to print all the elements of th +e %HoA—but I’m failing to do this inside the function. This is my pro +blem. (The same function that receives the HoA must also process an +array. ) some_function(\%HoA); # could be some_function(\@array) sub some_function{ $aref = shift; if (ref($aref) eq “ARRAY”){ Do something with array---I got this muchworking! } elsif (ref($aref) eq “HASH”){ #This foreach of the hash ref doesn't print anything! foreach $key ( keys %{$aref} ){ print “key: $key…..”; for ( $i = 0; $i <=100; $i++ ){ print “ $aref->{$key}[$i] “; } }
    Thanks for any clues. John
modulino and perldoc
1 direct reply — Read more / Contribute
by neilwatson
on Jul 10, 2014 at 15:43

    Greetings again,

    Regarding Modulino::Demo, specifically the following sections. How does the doc sub work? Is it supposed to run when the module is called using perldoc? I did try it, but I didn't see the s/__PACKAGE__/$package/; happen. Have I got it all wrong?

    UNITCHECK { sub _running_under_docreader { # << !! $ENV{PERLDOC} } sub _running_under_tester { !! $ENV{HARNESS_ACTIVE} } sub _running_as_app { defined scalar caller } my $method = do { if( _running_under_docreader() ) { 'doc' } # reading docs # << elsif( _running_under_tester() ) { 'test' } # testing elsif( _running_as_app() ) { 'run' } # running else { undef } # everything else }; sub doc { say "Running as docs"; my $data = do { local( @ARGV, $/ ) = __FILE__; <>; }; my $package = __PACKAGE__; $data =~ s/__PACKAGE__/$package/; # AND << say $data; }

    Neil Watson
    watson-wilson.ca

Moose, Class::DBI, and builder
1 direct reply — Read more / Contribute
by perldiverx
on Jul 10, 2014 at 14:59
    Hello, I'm having a problem getting a builder to run in a subclass. Whenever I try and run a script that calls $obj->{'manual_phone'} it comes back undefined and I'm not sure why. I thought this was supposed to be built when the accessor was called.
    Anyways, here's what I have.
    package Transaction; use Moose; use MyDB::Merchid; use Win32; has 'transaction_type' => ( is => 'rw', isa => 'Str', required => 1, ); has merch_info => ( is => 'ro', isa => 'Any', builder => '_build_merch_info', ); sub _build_merch_info { my $self = shift; my $snum = substr(Win32::NodeName, 5); return MyDB::Merchid->retrieve($snum); } 1; package MyDB; use strict; use warnings; use base 'Class::DBI'; MyDB->connection('dbi:ODBC:mydbsqldsn') || die "Couldn't connect to da +tabase: " . $DBI::errstr . "\n"; 1; package Transaction::CC; use Moose; extends(qw/Transaction/); has 'manual_phone' => ( is => 'ro', isa => 'Str', lazy_build => 1, ); sub _build_manual_phone { my $self = shift; if (! defined $self->{merch_info}) { die "ERROR: merch_info not defined\n"; } return $self->{merch_info}->MANUAL_NUMBER; } 1; package MyDB::Merchid; use strict; use warnings; use base 'MyDB'; MyDB::Merchid->table('MERCHID'); MyDB::Merchid->columns(All => qw/ COMPANY_NUMBER MERCHID_SIC_CODE MERCHID_QUAL_CODE MANUAL_NUMBER /); 1;
    A snippet from the script:
    my $obj = Transaction::CC->new( 'transaction_type' => 'Visa', ); print "\$obj->{'manual_phone'}: " . $obj->{'manual_phone'} . "\n";
installation of FireFox :: Mechanize fails - [again]
5 direct replies — Read more / Contribute
by Perlbeginner1
on Jul 10, 2014 at 14:40


    well i tried it several times - on differnet installations of suselinux. now - on opensuse 13.1 i have issues again to install mozrepl firefox

    - once - years ago i managed to get it up and running. but i do not know how... - unfortunatly

    FOLLOWED THE STEPS HERE:

    http://search.cpan.org/~corion/WWW-Mechanize-Firefox-0.74/lib/WWW/Mechanize/Firefox/Installation.pod

    Download mozrepl 1.1.0 available from
    https://github.com/bard/mozrepl/zipball/1.1.0
    or a later version from
    https://github.com/bard/mozrepl/tags Unpack the zip archive into a directory.
    The archive contains one subdirectory with a name of the form bard-mozrepl-abcdefg. Create a new zip archive with the files in the subdirectory bard-mozrepl-abcdefg. This new archive must have the files at the root entry, not in a subdirectory.


    The file layout should look like this:

    chrome/ components/ defaults/ chrome.manifest install.rdf logo.png



    Rename your new zip archive from .zip to .xpi.
    Launch Firefox
    Install the freshly created .xpi file into Firefox. For example you can drag and drop the file into Firefox. Start mozrepl in Firefox by going to the menu:

    well i did all the steps and finally i got the results

    drwxr-xr-x 5 martin users 4096 15. Dez 2011 bard-mozrepl-646208b martin@linux-70ce:~/perl/mechanize_firefox> cd bard-mozrepl-646208b/ martin@linux-70ce:~/perl/mechanize_firefox/bard-mozrepl-646208b> ls -l insgesamt 24 drwxr-xr-x 3 martin users 4096 15. Dez 2011 chrome -rw-r--r-- 1 martin users 722 15. Dez 2011 chrome.manifest drwxr-xr-x 2 martin users 4096 15. Dez 2011 components drwxr-xr-x 3 martin users 4096 15. Dez 2011 defaults -rw-r--r-- 1 martin users 1114 15. Dez 2011 install.rdf -rw-r--r-- 1 martin users 2166 15. Dez 2011 logo.png martin@linux-70ce:~/perl/mechanize_firefox/bard-mozrepl-646208b>


    I installed it trought firefox

    BUT then i tried to thest it:
    qestion: which tests can i do - which tests with the terminal to check if i installed it right? i found this site http://chat.stackoverflow.com/transcript/23922/2013/2/4/23-24 where someone claims that i can do the following test.

    add only this line in a file use WWW::Mechanize::Firefox;

    cf: Mooing Duck Does a file containing only "use WWW::Mechanize::Firefox;" work? If not, it's not properly set up. I'm still researching how to set up perl plugins for you. see this site http://chat.stackoverflow.com/transcript/23922/2013/2/4/23-24


    results:

    martin@linux-70ce:~/perl> perl moz.pl Can't locate WWW/Mechanize/Firefox.pm in @INC (you may need to install + the WWW::Mechanize::Firefox module) (@INC contains: /usr/lib/perl5/s +ite_perl/5.18.1/i586-linux-thread-multi /usr/lib/perl5/site_perl/5.18 +.1 /usr/lib/perl5/vendor_perl/5.18.1/i586-linux-thread-multi /usr/lib +/perl5/vendor_perl/5.18.1 /usr/lib/perl5/5.18.1/i586-linux-thread-mul +ti /usr/lib/perl5/5.18.1 /usr/lib/perl5/site_perl .) at moz.pl line 2 +. BEGIN failed--compilation aborted at moz.pl line 2. martin@linux-70ce:~/perl>



    well the installation of mechanize_firefox fails here

    what d o you advice!?
Windows SSH Help
2 direct replies — Read more / Contribute
by PerlCramps
on Jul 10, 2014 at 13:39
    I have strawberry perl working on my windows 7 laptop. I am trying to remote into some Brocade switches that I manage. I tried to load the Net-SSH-W32Perl module it fail because it has a requirment for Math-Pari module to be installed. I cannot get Math-Pari to install: it gives me the following error (did not find GP/PARI build directory around. Do you want to me to fetch GP/PARI automatically. The process fail for yes and no. Could someone please help me to get SSH working on my workstation. Thanks
modulino and $VERSION
2 direct replies — Read more / Contribute
by neilwatson
on Jul 10, 2014 at 13:35

    Greetings,

    I'm attempting to learn brian_d_foy's modulino. In this early prototype I'm getting an uninitialized error about $VERSION. What is the cause?

    #!/usr/bin/perl use strict; use warnings; use feature qw/say/; use vars qw/$VERSION/; $VERSION = 0.01; UNITCHECK { sub _running_under_docreader { !! $ENV{PERLDOC} } sub _running_under_tester { !! $ENV{HARNESS_ACTIVE} } sub _running_as_app { defined scalar caller } my $method = do { if( _running_under_docreader() ) { 'doc' } # reading docs elsif( _running_under_tester() ) { 'test' } # testing elsif( _running_as_app() ) { 'run' } # running the appli +cation else { undef } # everything else }; __PACKAGE__->$method(@ARGV) if defined $method; } sub run { say $VERSION; } $ ./foo.pl Use of uninitialized value $VERSION in say at ./foo.pl line 36.

    Neil Watson
    watson-wilson.ca


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 lurking in the Monastery: (4)
    As of 2014-07-12 20:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (241 votes), past polls