This question often comes up in the context of "how do I write a simple command line loop"?
There are very few times in 'C' or in Perl where the comma operator makes sense to use, but this is one of them! This is an interactive thing that you can play with...go for it! Fiddle with the regex and see what it does!
Some Monks prefer more complex formulations of this command line loop algorithm. I think the important part here is for you to understand how to "drive the regex part".
#!/usr/bin/perl -w use strict; while ( (print "Enter some text: "), (my $line=<STDIN>) !~ /^\s*q(uit)?\s*$/i ) { next if $line =~ /^\s*$/; #blank line just re-prompts chomp ($line); # a real app would probably do this print "$line\n"; # although here I just add it back } print "program exited\n"; __END__ C:\TEMP>stdcmdline.pl Enter some text: 25436 25436 Enter some text: QuIT progam exited C:\TEMP>stdcmdline.pl Enter some text: quI quI Enter some text: Q progam exited C:\TEMP>stdcmdline.pl Enter some text: asdf asdf Enter some text: qu qu Enter some text: QuIT program exited C:\TEMP>stdcmdline.pl Enter some text: quited quited Enter some text: 3245 3245 Enter some text: Q program exited C:\TEMP>stdcmdline.pl Enter some text: q program exited C:\TEMP>stdcmdline.pl Enter some text: quit program exited
In reply to Re: conditional regex
by Marshall
in thread conditional regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |