Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: hashing and arrays issue

by toolic (Bishop)
on Apr 09, 2015 at 15:40 UTC ( [id://1122963]=note: print w/replies, xml ) Need Help??


in reply to hasing and arrays issue

It looks like you only need an array:
use warnings; use strict; my @svcArray; while (<DATA>) { chomp; push @svcArray, (split /:/, $_, 3)[2]; } my $i = 1; for (@svcArray) { print "$i. $_\n"; $i++; } __DATA__ HR:1453:Recruitment:Up FS:2355:Payments:Down RS:4555:Retail:Up LD:682111:Legal:Up

Prints:

1. Recruitment:Up 2. Payments:Down 3. Retail:Up 4. Legal:Up

But, if you need to store more data, a hash may also be suitable. Refer to perldsc

Replies are listed 'Best First'.
Re^2: hashing and arrays issue
by perlDevsWorld (Novice) on Apr 15, 2015 at 07:38 UTC

    My updated code works for single inputs and for all but planning to extend this functionality by accepting comma seperated values. Need help with this. Thanks in advance!

    host(); my $it=1; my %appHash=(); if($it == 1){ open(INPUTFILE,"<Services.conf")or die("unable to Services fiel"); while (<INPUTFILE>) { chomp; push @svcArray, (split /:/, $_, 3)[2]; } foreach my $svc (@svcArray){ $appHash{it} = $svc; print "\n\t\t\t$it. $appHash{$it}\n"; $size = $it; $it++; } print "\n"; print "\t\t\tA for All \n"; print "Please choose a number from the list above: "; chop($input=<STDIN>); $input=trim($input); print " The input after chopping:$input\n"; } my $appCmnStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelo +pe xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"> <env:Body> <oos:req xmlns:oos=\"http: +//www.ecomm.com\">; send_svc($input); exit(0); ################# sub send_svc{ my @aArray; if(@_[0] && (lc @_[0] ne 'z')){ @aArray = (@_[0]); }else{ @aArray= (1 .. $size); } foreach $svcObjNum (@aArray){ if($appHash{$svcObjNum}){ $appsStr = $appsStr."<oos:obj class=\"$appHash{$svcObjNum}"/>"; } }

    from here I concatenate the XML lines and make a post to service. All working well for single input or z which is for all. But need some assistance how can I achieve this for multiple input values comma or space separated. With the fact that need to from those XML lines based on the options users select and then post it to my service

    On console it looks like below option

    1. Recruitment 2. Payments 3. Retail 4. Legal z. all Please choose a number from the list above:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1122963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found