Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
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.

Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2012  (Don't worry; you've got plenty of time.)

New Questions
Read data from csv file to a data structure format
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 18, 2012 at 02:59
    Hi Perlmonks,
    I would like to create a data structure from a csv file.

    The sample csv file as follows

    Product Name,Product Code,Company1,Company2,Company3 Test One,C001,Y,N,N Test Two,C002,N,N,Y Test Three,C003,Y,Y,N

    and I am looking for an output in the below format
    { Company1 => {C001 => Y, C002 => N, C003 => Y}, Company2 => {C001 => N, C002 => N, C003 => Y}, Company3 => {C001 => Y, C002 => Y, C003 => N} }

    I tried using Text::CSV_XS module, but not able form a structure as mentioned above
    use Text::CSV_XS; my $csv = Text::CSV_XS->new(); open my $FH, "<", "test.csv"; while (<$FH>) { $csv->parse($_); my @fields = $csv->fields;
    Is there any CPAN module available to get this structure
    Can you please help on this.
    Thanks
Links between Mason components?
2 direct replies — Read more / Contribute
by tye
on May 17, 2012 at 13:15

    Have I just not found it? It seems a pretty basic, fundamental, and important feature. And I have not yet found any built-in support in HTML::Mason for constructing a link (as in <a href=...) from one Mason component to another where that link includes arguments.

    That is, other than a quite awkward construction like:

    <a href="/path/to/component?who=<% $who |u %>;why=<% $why |u %>"> Title goes here</a>

    Having to remember to include "|u" for each parameter makes that nearly unacceptable in my book (after seeing way too many bugs from lack of URL escaping that pass unnoticed for a long time and then turn into a crisis, even a security problem). It also gets quite tedious (and error-prone and hard to read) when producing a table full of similar links.

    But to see how awkward that really can be, imagine what I find to be a common case: Having a hash of arguments that you want to include in the link. Am I really supposed to roll my own URL constructor for such an obvious case?

    <& .link, 'Edit Settings', '/widget/settings', %Context &> ... <%def .link> % my( $title, $page, %args ) = @_; <a href="<% $page %>? % for my $key ( sort keys %args ) { <% $key |u %>=<% $args{$key} |u %>; % } "><% $title |h %></a> </%def>

    Although that first line is a reasonable interface, the implementation, of course, doesn't actually work, producing:

    <a href="/widget/settings? acct=some_acct%23id; widget=widget%2Bid; ">Edit Settings</a>

    Is there a better (and actually correct) way to write such in Mason?

    Too bad defining a "removing newlines and adjacent whitespace" Mason filter (call it "|w") doesn't allow me to address this problem as simply as:

    <& .link, 'Edit Settings', '/widget/settings', %Context |w &>

    (You can use "|w" inside of <% ... %> but not inside of <& ... &>.)

    So, (at least for now) I resign myself to looking outside of Mason for a solution.

    So, I roll these pieces together and get:

    And try to use that in my Mason:

    Note the gyrations to prevent .link from including newlines.

    Okay, that is quite a bit uglier than I had hoped for. But it actually works.

    But it quickly demonstrated how it wasn't very flexible when I tried to use it in a page that uses JavaScript to generate a list of links client-side (also changing it to not take a hash of parameters but instead just a comma-separated list of key names used to look up the parameter names and values that are ever used from this page):

    <& .link, "Edit $widget_name Settings", 'settings', 'acct,widg' &> ... <script type="text/javascript"> ... + '<& .link, "Edit {{feature_name}}", 'edit', 'acct,widg,feat' + &>'

    Where the new .link replaces the ',feat' with feature_id => '{{feature_id}}' and the JavaScript replaces '{{feature_name}}' and '{{feature_id}}' with values that vary between rows (one row generated per feature).

    There is a risk that the second call to .link above would include something (a ', a \, or a newline) that wouldn't be legal inside of a JavaScript string. That sounds like a job for a Mason filter. I could define "|l" to strip newlines (a common desire when using Mason, it seems) and "|sq" to escape those problem characters.

    Oh, except, as we already mentioned, you can't use something like "|sq" with <& ... &>.

    I could define .sq that escapes the string passed to it. Ooh, I just found this syntax:

    + '<&| .sq &><& .link, ... &></&>'

    That actually addresses (if in a manner still uglier than I had hoped) some of the questions I had when I started writing this.

    What other features am I missing? How can I do this better?

    - tye        

CPAN - error with installation
3 direct replies — Read more / Contribute
by Jeri
on May 17, 2012 at 12:03

    Hi, I'm trying to set up cpan on Ubuntu 12.04 LTS. In the terminal I wrote

    sudo perl -MCPAN -e shell
    make install
    install Bundle::CPAN

    I've done an update and upgrade and have also installed perl. When I try to download XML::Parser in cpan it complains

    make: *** [subdirs] Error 2 TODDR/XML-Parser-2.41.tar.gz /usr/bin/make -- NOT OK Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible Failed during this command: TODDR/XML-Parser-2.41.tar.gz : make NO

    This happens with any module I try to download. I noticed it was discussed in this 2010 thread http://www.perlmonks.org/?node_id=866275 with no luck. Any help solving the cause of this error would be appreciated.

    Thanks in advance!

Keeping tags in regex
3 direct replies — Read more / Contribute
by Anonymous Monk
on May 17, 2012 at 11:41

    Hello monks,

    I am doing some substitutions of strings with a regex. For example, I have code like this:

    %dictionary = (foo => 'bar', baz => 'w00t'); $str =~ s[$_][$dictionary{$_}] for keys %dictionary;
    But now the problem is that some of the words have embedded XML tags. I would like to still perform the substition but keep the XML tag. There is at most one XML tag in a word; for example: <tag>f</tag>oo should become  <tag>b</tag>ar

    and

     <b>fo</b>o should become <b>ba</b>r

    Is there a simple way of doing this without writing out all of the possible combinations? Thanks!

splitting data
1 direct reply — Read more / Contribute
by BluGeni
on May 16, 2012 at 12:01
    I am trying to get a grasp on splitting strings and arrays with perl but am having a little problem. my first page puts data into a database so it can be called upon later. its going in like this:
    $writetot=$busitotal."/".$perstotal; $STH1->execute($writetot,$name)
    and is being called by data1 , data2 ect.. my goal here is to split $writetot so i have 2 different outcomes and don't have it displaying $busitotal/$perstotal. I need to split it because of the data already in the data base will not change and i need to separate the 2 so i can put $busitotal and $perstotal in 2 dif catagories. any help would be greatly appreciated! Thank you
TLS using Perl < 5.12?
1 direct reply — Read more / Contribute
by talexb
on May 16, 2012 at 09:53

    I'd like to know if it's possible to get older Perls (earlier than 5.12.x) to talk TLS. I'm working on using SOAP::Lite to talk to an API; reading the documentation on this module, it isn't immediately apparent whether I can ask earlier Perls to make a TLS connection rather than the default SSLv3 connection.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Expected speed of retrieve function (nstore retrieve)
4 direct replies — Read more / Contribute
by rjbioinf
on May 16, 2012 at 07:01
    Hello, I have an array stored using 'nstore' method. The resulting dump file is 90Mb (40 million elements). When I load it back into Perl using 'retrieve' it takes > 5 minutes. I have never really looked into the speed of this operation much before as I have never been left waiting as it were. I wonder if you would expect the retrieve process to take this long or is something amiss? I am running a new 4gig ram macbook pro with Lion so it should be pretty quick i would have thought? cheers,
Help required on Getopt::Long
5 direct replies — Read more / Contribute
by ghosh123
on May 16, 2012 at 05:32

    Hi Monk,
    In my program, I am using the module Getopt::Long My intension is that if the user chooses "--help", the program should show the help message without bothering whether other options has been used or not. My program (say, test.pl) :

    use Getopt::Long my $abc; my $help; GetOptions ( "abc=s" => \$abc, "help" => \$help ); if ($help) { print "This is help message\n" ; exit ;} if ($abc) { print "You have choosen \"abc\" as $abc" };

    If I run this:
    1. test.pl -help
    Output: This is help message

    2. test.pl -abc ABC
    Output : You have choosen abc as ABC

    3. test.pl -abc -help
    Output: You have choosen abc as -help

    Out of the above results 1 & 2 are fine, but 3 is not as I want. I understand what's happening here $abc is assigned as "-help", but don't have idea how to implement it properly so that in the 3rd it would print like " This is help message" .

    Can anybody help please ?
    Thanks and regards

Docs for TARG / targ
2 direct replies — Read more / Contribute
by aufflick
on May 15, 2012 at 21:05
    Hi all,

    I've looked before for useful docs on TARG / targ / op_targ / TARGET etc. and when/how it can be set so as to use the more efficient POP* functions among other things.

    I had never found anything written about it until I stumbled across this fairly useful post on the perl.perl5.porters news group:

    Re: Tantalized by TARG (Was: (patch) Cwd.xs optimizations/abstraction)]

    Can anyone suggest any other useful docs/discussions on TARG?

    PS: If you have no idea what I'm talking about, TARG is an XS thing :)

Safe and sharing variables
1 direct reply — Read more / Contribute
by goehle
on May 15, 2012 at 10:09

    I'm sure that this is a fairly simple question, but its still giving me fits. How do you share variables when using Safe? There isn't a lot of documentation on Safe.pm and I can't seem to figure this out. The following code *should* print 7 when its run. Instead it doesn't print anything.

    use Safe; my $maxCounter = 7; my $testCode = 'return $maxCounter;'; my $container = new Safe; $container -> share('$maxCounter'); print $container->reval($testCode)."\n";
Splitting compound (concatenated) words )
7 direct replies — Read more / Contribute
by vit
on May 15, 2012 at 10:01
    Dear Monks,
    Could someone recommend a working perl module to split concatenated words.
cpan "r" command, of perl 5.15.9, does not show all of the installed modules
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 15, 2012 at 07:51

    I recently installed perl 5.15.9 (a developer release). I am in process of installing various modules via cpan. I noticed that "r" command lists only a few modules ...

    ... some of the modules not listed are DateTime, Scalar::Util, Term::Read(Key|Line*). (These also do not appear in show_unparsable_version list.) Needless to say r /DateTime/ and r /./ also fail to show, e.g. DateTime, module version status.

    Has anybody noticed this? Am I missing somthing?

New Monk Discussion
PerlMonks site design
10 direct replies — Read more / Contribute
by kimmel
on May 16, 2012 at 16:07

    So I made a comment on reddit the other day about the PerlMonks site design: http://www.reddit.com/r/perl/comments/tlied/becoming_a_friar_on_perlmonks/

    TL;DR: No one's done the work on a new PerlMonks site design.

    Challenge issued, challenge accepted :) I downloaded a copy of the front page and got to work. I have 3 primary goals with this redesign attempt.

    1. Tableless layout
    2. Responsive on cellphones and other small screen devices.
    3. Less visual clutter
    

    I am not changing the color scheme or the layout so it looks the same as it does now.

    Can someone post the templates that generate the pages and sections so I can verify that my changes will fit?

    I am waiting on the rest of my browser shots of the site and then I will make another post with a link to a github account containing the new design as well as screenshots of the current site versus the new one on desktop browsers and on cellphones. Are there any 'gotchas' I should know about for working on this project? Bring on the commentary!
What is this "ChatterBox" of which you Speak?
3 direct replies — Read more / Contribute
by Clovis_Sangrail
on May 14, 2012 at 13:45

    In the "Seekers of Pearl Wisdom" section you write:

    "If you have a question on...However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker..."

    But I can find no section labeled "ChatterBox". I suspect that you mean "The Monastery Gates" but that occured to me after I posted my question in the "Seekers of Perl Wisdom" section.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2012-05-18 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favourite stuffed toy is a(n)…



























    Results (536 votes), past polls