By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,245 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,245 IT Pros & Developers. It's quick & easy.

Perl code for spiltting numerical value from a input file

P: 2
can any one give a code for spilitting a numerical value randomly from a input file.....
Feb 11 '08 #1
Share this Question
Share on Google+
5 Replies


eWish
Expert 100+
P: 971
What have you tried? We need some effort here...

--Kevin
Feb 11 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
What have you tried? We need some effort here...

--Kevin

Yes, and an example of whatever the hell-o that vague requirement actually means would be helpful too.
Feb 11 '08 #3

Kelicula
Expert 100+
P: 176
Here ya go!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl -T
  3.  
  4. my $inputfile = '/dir/file.txt';
  5.  
  6. $input = $inputfile =~ s/\d*/$1/;
  7. @input = split(//,$input);
  8.  
  9. $result = $input[int(rand($#input))]
  10.  
  11. # $result is now a random "split" number from an input file !! heheheee.... :)
  12.  
  13.  
That's what you get.

Sorry guys, I'm in a mood... hehehee
Feb 11 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
Really man! Can't you see that the Kevin's were trying to get the OP to provide the code that they have been trying? This is a learning forum, not a code writing service. Of course, you just gave him the answer to what could have been school work.

Please do not do that again, it completely undermines our efforts to have the OPs learn from their questions.

Regards,

MODERATOR
Feb 11 '08 #5

Kelicula
Expert 100+
P: 176
Really man! Can't you see that the Kevin's were trying to get the OP to provide the code that they have been trying? This is a learning forum, not a code writing service. Of course, you just gave him the answer to what could have been school work.

Please do not do that again, it completely undermines our efforts to have the OPs learn from their questions.

Regards,

MODERATOR

I apologize.
Did you look at the code?

All it does is see if there are any 0-9's present within the "name" of a file.
If so it omit's everything but them.
And splits them into an array, and returns a random one of them

So you see it: "can any one give a code for spilitting a numerical value randomly from a input file".

I was trying to prove to him that with such a vague question, you'll get a vague (most likely not effective) answer.

(It probably doesn't even work)

But I knew when I posted it, that it may be out of line.
Making fun of OP's.

For that I apologize.

Won't happen again.
Feb 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.