?
Solved

(join / split / hash) combination

Posted on 2007-07-30
6
Medium Priority
?
164 Views
Last Modified: 2013-12-25
I use this code :

%LANG = (LANG1=>"Dutch",LANG2=>"English",LANG3=>"French");
print join(", ", split /\n/,$record->{'languages'});

this is the output:

LANG1,LANG2,LANG3

But the output need to be the values from the %LANG Hash... How I get this? I want it in one line.. So not with a WHILE LOOP. :-)

Thanx!
0
Comment
Question by:netdreams
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:mjcoyne
ID: 19591775
Something like:

#!/usr/bin/perl -w
use strict;

my %LANG = (LANG1=>"Dutch",LANG2=>"English",LANG3=>"French");

print join ", ", values %LANG;

Maybe?  The output is 'French, English, Dutch'.  If you need the outout to be 'Dutch, English, French', you can do:

#!/usr/bin/perl -w
use strict;

my %LANG = (LANG1=>"Dutch",LANG2=>"English",LANG3=>"French");

print join ", ", reverse values %LANG;

It's tough to check further without knowing what $record is doing...
0
 

Author Comment

by:netdreams
ID: 19591929
I don't need to print all hash values all the time... it's depending on the keys in $record...
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 19592100
If $record->{'languages'} is returning the keys to %LANG, then the values of %LANG should be returned by $LANG{$record->{'languages'}}...?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 

Author Comment

by:netdreams
ID: 19592201
Yes I know, but how can I integrate this in the line:

print join(", ", split /\n/,$record->{'languages'});

?

0
 
LVL 39

Accepted Solution

by:
Adam314 earned 375 total points
ID: 19592678
I'm not clear on what you want.  Does $record->{'languages'} contain a list of the keys for %LANG?  If so, try this:

print join(", ", @LANG{split(/\n/, $record->{languages})});
0
 

Author Comment

by:netdreams
ID: 19592732
That's exact what i ment. Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question