File: underscore.pl

package info (click to toggle)
libio-prompt-perl 0.997004-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 228 kB
  • sloc: perl: 846; makefile: 2
file content (33 lines) | stat: -rwxr-xr-x 688 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl

use IO::Prompt;

# This example demostrates how prompt autosets $_ when appropriate

# Case 1...
undef $_;
my $first = prompt "1> ";
print defined() ? "(\$_ was '$_')\n" : "(\$_ was undef)\n";
print "Got: $first\n";

# Case 2...
undef $_;
prompt "2> ";
print defined() ? "(\$_ was '$_')\n" : "(\$_ was undef)\n";
print "Got: [$_]\n";

# Case 3...
undef $_;
while (prompt "3> ") {
    print defined() ? "(\$_ was '$_')\n" : "(\$_ was undef)\n";
    print "Got: [$_]\n";
    last if $_ ne "\n";
}

# Case 4...
undef $_;
while (my $next = prompt "4> ") {
    print defined() ? "(\$_ was '$_')\n" : "(\$_ was undef)\n";
    print "Got: $next\n";
    last if $next ne "\n";
}