Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
Escaping special characters in Password prompt to be passed onto SAP-CRM
3 direct replies — Read more / Contribute
by rajrev-snps
on Jun 23, 2016 at 12:09

    I'd like to parse and escape any special characters in the Password and pass the literal text to a SAP-CRM system for logging-in the user. Of course, I'm trying to achieve this in Perl.

    Here is the regular expression that I'm using

    /[\~]+|[\!]+|[\@]+|[\#]+|[\%]+|[\&]+|[\-]+|[\_]+|[\:]+|[\;]+|[\']+|[\"]+|[\<]+|[\>]+|[\,]+|[\.]+|[\\]+|[\+]+|[\*]+|[\?]+|[\^]+|[\$]+|[\{]+|[\}]+|[\(]+|[\)]+|[\|]+|[\/]+|[\]]+|[\[]+|[\t]+/g

    Almost every character gets escaped except for the "$" character

    Please advise?

Open() : Not reading all lines in my text file
4 direct replies — Read more / Contribute
by Anusha_26
on Jun 23, 2016 at 06:10

    I have a text file(like posted below),

    anusha ramegowda <perl programming1234> "23rd June 2016" #Thursday, 11:05am# <perl programming5678> problem encountered

    I'm trying to read the contents of the text file(titlefile) using

     open (my $fp, "<", $titlefile) or die "Can't open <$titlefile: $!";  

    It reads all contents except the ones within <chevrons> for e.g. I don't read <perl programming1234> and <perl programming5678>.

    I want to read the string within chevrons to able to distinguish between various values. Can anybody please help?

Timeout 0 in LWP::UserAgent
2 direct replies — Read more / Contribute
by perl_help26
on Jun 23, 2016 at 05:36
    Hello, I have a small question. When you set the timeout to be 0 in LWP::UserAgent post request, will this mean that it will not wait for the response or will it take the default timeout? How about timeout -1? Thanks
Transfer file from client server in socket prog
1 direct reply — Read more / Contribute
by t-rex
on Jun 23, 2016 at 04:39

    i have implemented a concurrent server model , now i wish to transfer files from client to server , i checked send() api of the socket but in that i can't directly send the file , so i want to know what are the best options to transfer a file, can i use OpenSSH module (scp functions in that for transfer) ? I have read few old posts but none have used send directly to transfer files they have used file handles for some processing. pls help

Why do I (sometimes) get a REF ref and not a SCALAR ref?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 23, 2016 at 00:22

    Can anyone give an explanation of the following Perl behavior?

    $ perl -le 'my $a = "foo"; my $b = \$a; print $b'
    SCALAR(0x7f95b98299c8)
    $ perl -le 'my $a = "foo"; $a = \$a; print $a'
    REF(0x7f9b608299c8)
    $ perl -le 'my $a = "foo"; my $b = $a; $a = \$b; print $a'
    SCALAR(0x7f82d88299e0)
    $ perl -le 'my $a = "foo"; my $b = \$a; $a = $b; print $a'
    REF(0x7fab830299c8)
    

    What I would expect is for all the above to produce a SCALAR. I'm tempted to call this a bug, but I have gotten this behavior with 5.25.2, 5.24.0, 5.22.2, 5.20.2, and 5.8.9, so you would think if it was a bug someone would have noticed before now. So what gives?

Perl Formatting Text
4 direct replies — Read more / Contribute
by oopl1999
on Jun 22, 2016 at 20:04

    Hi, I am extremely new to Perl and any help would be appreciated. So I have data in text form such as this:

    A 1 B 3 6 2 C 3 4 6 2 10

    This is just an example, the actual data is much more complex and long. I need to be able to parse the data from a text file then output the data in the following format into another text file:

    A 1 B 2 B 3 B 6 C 2 C 3 C 4 C 6 C 10

    The problem is that I wont know how many row or columns the data has. In other words, I don't know how many letters there are or how many numbers each letter has. Can anyone help me with this or give me any pointers?

How to split main package into multiple files
3 direct replies — Read more / Contribute
by mmk
on Jun 22, 2016 at 19:01

    According to the Book, "Packages are independent of files. You can have ... a single package that spans several files" (Chapter 10: Packages).

    How can we split the default (main) package into multiple files and link them in the correct order when we compile and run?

    Thanks!

    Edit:

    PS. I know how to organize codes using Perl modules. This question is not about how to write Perl modules or even how to split Perl modules into multiple files with .al extensions.

naming anonymous subroutines inner variables
6 direct replies — Read more / Contribute
by writch
on Jun 22, 2016 at 16:04
    I might be being a bit more clever than I should be, but it seemed such a good idea at the time.

    I have some heavily query driven code. I intended to use a hash of SQL queries to build out a number of prepared queries. That part is working fine.

    Then, I realized, rather than write functions to return the result sets, I maybe could, in the same loop which is doing the preparation of the queries, make an anonymous subroutine and assign it, rather than writing it by hand.

    The problem is in the sixth line. When I do my 'test' query, $self->{test} is the prepared query, and $self->{ftest}() is the code that would execute it.

    But the $_ that turned out fine in the earlier uses is useless in the code itself.

    The error is 'Can't call method "execute" on an undefined value' because (of course) the line is actaully $self->{}->execute(@_) instead of $self->{test}->execute(@_), as $_ isn't populated when it's being executed, just when it's being created.

    for (keys %{$self->{SQL}}) { $self->{$_} = $self->{DBO}->prepare($self->{SQL}->{$_}); $self->{"f$_"} = sub { my $self = shift; my @res; $self->{$_}->execute(@_); while (my $dbrow = $self->{$_}->fetchrow_h +ashref()) { push @res, \$dbrow; } return \@res; }; }
Surprising capture of undef with zero repetitions
4 direct replies — Read more / Contribute
by bengo
on Jun 22, 2016 at 13:14
    % perl use warnings; use strict; use Data::Dumper; sub f { my @tmp = "list $_[0]\n" =~ /^list\s+(\w+)(?:,(\w+))*$/m; print(Dumper(\@tmp)); } f("foo"); f("foo,bar"); # Ctrl-D $VAR1 = [ 'foo', undef ]; $VAR1 = [ 'foo', 'bar' ];

    Dear Enlightened Monks,

    I was somewhat surprised to find this "extra" undef returned here, when I expected/wanted only "foo".
    Can you explain why this happens? (preferably without reference to use re 'debug' ;)
    Is there any way to tweak my regex to avoid it?

    I'm assuming that this is a feature, not a bugTM, and there isn't an easy way to make Perl itself less surprising in the general case...?

    Thanks!

xlsx to csv ssconvert
1 direct reply — Read more / Contribute
by perlUser345
on Jun 22, 2016 at 12:37

    Hey monks!
    I'm trying to convert an xlsx file to csv. So far I've been able to use ssconvert just fine, however I'm having some problems with one particular xlsx file. This file has a drop down menu for a few entries and ssconvert gives a segmentation fault.
    I cannot use Spreadsheet::ParseExcel because I can't install anything on my machine (not admin). I tried the python xlsx2csv.py with no luck.
    Any idea on how to make this work with ssconvert?
    Thanks!


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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (6)
    As of 2016-06-26 07:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My preferred method of making French fries (chips) is in a ...











      Results (328 votes). Check out past polls.