in reply to making a list and saving results

Here:

#!/usr/bin/perl use warnings; use strict; print "enter the 1st number: \n"; chomp( my $number1 = <STDIN>); print "enter 2nd number: \n"; chomp( my $number2 = <STDIN>); my @list=($number1..$number2); { local $" = "\n"; open my $fh, '>', "$ENV{HOME}/number_list.txt" or die $!; print $fh "@list\n"; }
The bare block is to restrict the dynamic scope of $" and the lexical scope of $fh. That makes $fh be closed as soon as the block is exited. $" contains the element spacer text used for stringifying arrays.

I've added warnings and strict to help you in future.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: making a list
by surfbass (Initiate) on May 29, 2005 at 20:33 UTC
    thanks, but how could i add a prefix to those numbers? like
    something1 something2 something3
    etc., etc.
      I like it dirt - instead of
      { local $" = "\n"; open my $fh, '>', "$ENV{HOME}/number_list.txt" or die $!; print $fh "@list\n"; }
      use
      my $prefix = "something"; { local $" = "\n$prefix"; open my $fh, '>', "$ENV{HOME}/number_list.txt" or die $!; print $fh "$prefix@list\n"; }
      Of course it's just to show you that you can put whatever separator inside $"; if you want a clean solution, use Zaxo's.

      Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

      Don't fool yourself.

          print $fh "@{[ map { 'something' . $_ } @list ]}\n";

      Added: Or else you could decorate them beforehand: my @list = map { 'something' . $_ } $number1 .. $number2;

      After Compline,
      Zaxo