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

XML Simple

by Arenas (Novice)
on May 31, 2015 at 12:03 UTC ( [id://1128475]=perlquestion: print w/replies, xml ) Need Help??

Arenas has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: XML Simple
by toolic (Bishop) on May 31, 2015 at 12:12 UTC
      Thanks for your reply!

      I have see the chapter for 'how format numbers is this the only way to format numbers with regex?

      Do you have links to get dif. xml modules?

      Best regards

      @r

        use Number::Format; my $x = new Number::Format(-thousands_sep => ' '); my $number = 1234567890; print $x->format_number($number);
        $ perl example.pl 1 234 567 890

        You will need to install Number::Format from CPAN (see other answer)

        You can also try this, but it does not take into account numbers with comma's:

        my $number = 1234567890; print format_number($number); sub format_number{ my($x) = @_; $x = reverse $x; $x =~ s/(\d{3})/$1 /g; $x = reverse $x; return $x; }

        This prints:

        1 234 567 890
        You can search for modules at .
Re: XML Simple
by FreeBeerReekingMonk (Deacon) on May 31, 2015 at 21:55 UTC

    LWP (for "Library for WWW in Perl", also called libwww-perl) is a set of Perl modules that give Perl programming easy access to sending requests to the World Wide Web.

    Howto update in Strawberry perl: open CPAN

    perl -MCPAN -e shell

    Search for a library, for example LWP:

    i /libwww/

    This gives you a list, you can install one (for me this is)

    install GAAS/libwww-perl-5.837.tar.gz

    You can also search for the XML::Simple

    i /XML::Simple/

    I get a list and I can install from:

    install GRANTM/XML-Simple-2.20.tar.gz

    Now you can type "exit" to get out of CPAN and try to use XML::Simple;

Re: XML Simple
by Discipulus (Canon) on Jun 01, 2015 at 08:33 UTC
    Welcome to Perl and to the monastery Arenas,

    powershell is not a programming language, so you probably can profit from some basic reading about Perl as the book Beginning Perl or the (old but still usefull) Perl Cookbook.
    Some sparse suggestion being you new to Perl and using winz: you can check if you have a Perl's module installed with a simple oneliner (take a look at perldoc about command line switches)
    perl -MNot::Installed::Module -e "1"
    You are executing (-e) an always-return-true mini Perl program (what is inside the doublequote) but loading some module (after the -M ) before runnig the code. You obviosly get:
    Can't locate Not/Installed/Module.pm in @INC (@INC contains:...
    You can install modules using the cpanp client (working in the strawberry Perl distro on which DWimPerl is built)
    cpanp -i Not::Installed::Module
    Choose carefully module to install and use: XML::Simple is simply deprecated. Other modules are better but you need to learn how to use them: the following, working, code uses XML::Twig for xml parsing: anyway, even if you use a good module, xml parsing is a little triky and shaggy thing.
    #!perl use strict; use warnings; use XML::Twig; my $t= XML::Twig->new(pretty_print => 'indented', twig_handlers => { 'city/name'=>sub{ print $_[1]->text,"\n"; } +, 'city/population'=>sub{ print "Pop: ",$_[1] +->text,"\n"; }, } ); $t->parseurl('http://athome.myminicity.com/xml'); __OUTPUT__ AtHome Pop: 18998557

    As last suggestion, when asking here at perlmonks, do your best to present a simple and fully understandable question, with code that reproduce the error you are facing, or being clear about data you have and data you want to get back from your program. Asking clear question let you to have in return good answers, sometimes real gems, lurking here very wise and experienced programmers (not me).

    htH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      "powershell is not a programming language"

      I think the OP means Power Shell Scripting Language which is one.

      The inevitable example:

      [int]$i = 99; for($i=99; $i -gt 0; $i--) { write-host $i " bottles of beer on the wall"; write-host $i " bottles of beer"; write-host "Take one down, pass it around" write-host ($i-1) " bottles of beer on the wall" write-host "" }

      Please see also rosettacode and monad.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      Hello!

      Many thanks to all of your help!

      I will do: 'Choose carefully module'

      Impossible to download 'Number::Format'

      Probable my probleme is, I work with Vista 64

      @htH = Artist:

      I will also look for! => XML::Twig (great help!)

      This is transforment from powershell (excel) script => html. Now i will change and us GDI files

      http://arenas.pagesperso-orange.fr/mmc/simulation-athome-mmc.html

      All files togeter

      http://arenas.pagesperso-orange.fr/mmc/default-menu-Ville.html

      Greting

      @r

      Good Morning,

      I have reinstall perl (\Dwim), and only one version! So I m ready now.

      Please: How selecte singelnode nestet with Twig. and holdet by my $var =? (in the future so i can add math formula) (With Shell was : $xbcom = (xml$xdxml).selectSingleNode("city/bases/@com").$xt)

      How cleen variable: all or selective

      Thanks @r

      Nota bene:

      I don't was able to install "format number". Regex is good to do.

      my $VarNum = "14589965321"; # or "my $xbcom =" $ins =~ s/(\d)(?=(\d{3})+(?!\d))/$1 /g; print "$VarNum\n";
Re: XML Simple
by FreeBeerReekingMonk (Deacon) on May 31, 2015 at 22:33 UTC

    Also, please structure your questions a bit more.


    ...and welcome to PerlMonks. (bienvenido a PerlMonks)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1128475]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found