in reply to Re^2: Show different text based on random number
in thread Show different text based on random number

If you have your text in individual files, you could do something like this (with the help of Path::Tiny):
#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; my @choices = ( path('c1.txt'), path('c2.txt'), path('c3.txt'), path('c4.txt'), ); my $random_path = $choices[rand scalar @choices]; my $text = $random_path->slurp; print "The text is: $text\n"; exit;

Replies are listed 'Best First'.
Re^4: Show different text based on random number
by htmanning (Friar) on Apr 22, 2016 at 05:48 UTC
    Thanks. Do I have something wrong? This doesn't work:
    use Path::Tiny; my @choices = ( path('/usr/home/test/public_html/front-one.txt'), path('/usr/home/test/public_html/front-two.txt'), path('/usr/home/test/public_html/front-three.txt'), ); my $random_path = $choices[rand scalar @choices]; my $text = $random_path->slurp; print "$text";
      What do you mean by "doesn't work"? Are you getting any output at all, such as an error message? As far as I can tell, your code should work. Check the following:
      • Is Path::Tiny installed?
      • Check your file permissions. Do you have read access to those files?
        No errors. The text just doesn't display. I have the right permissions. I'll confirm whether its installed. I'm pretty sure it is. Thanks.