CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
using the contents of a variable for qw

 



theguyinthehat
New User

Nov 23, 2009, 1:10 AM

Post #1 of 3 (858 views)
using the contents of a variable for qw Can't Post

Is it possible? Say I save <STDIV> to a string, then I want each word to be a separate index in an array, ie.

#i know this code doesn't compile, but its what i want to do
@fred = qw( <STDIV>);
#where user enters 'one two three four'
#such that:
$fred[0] == one
$fred[1] == two

is there a way of doing this? Thanks!


7stud
Enthusiast

Nov 23, 2009, 5:01 AM

Post #2 of 3 (853 views)
Re: [theguyinthehat] using the contents of a variable for qw [In reply to] Can't Post

What is STDIV ??


Code
use strict; 
use warnings;
use 5.010;

print "Enter some words: ";
my @words = split /\s+/, <STDIN>;

say "-" x 20;
say for @words;


--output:--
Enter some words: one two three four
--------------------
one
two
three
four

qw{} makes strings. Input from STDIN is already a string. What made you think this was an Intermediate question? Do you consider yourself an Intermediate programmer?


(This post was edited by 7stud on Nov 23, 2009, 5:11 AM)


theguyinthehat
New User

Nov 23, 2009, 5:29 AM

Post #3 of 3 (840 views)
Re: [7stud] using the contents of a variable for qw [In reply to] Can't Post

I don't consider myself an intermediate programmer in Perl--I falsely assumed this was a question outside the scope of beginner. I'll post there with any further questions.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives