@@ -6,56 +6,58 @@ use Getopt::Long qw(:config no_ignore_case);
66use Pod::Usage;
77use Data::Random::String::Matches;
88
9- our $VERSION = ' 0.01 ' ;
9+ our $VERSION = ' 0.02 ' ;
1010
1111# Parse command line options
1212my %opts = (
13- count => 1,
14- length => undef ,
15- smart => 0,
16- separator => " \n " ,
17- help => 0,
18- man => 0,
19- version => 0,
20- examples => 0,
13+ count => 1,
14+ length => undef ,
15+ smart => 0,
16+ unique => 0,
17+ separator => " \n " ,
18+ help => 0,
19+ man => 0,
20+ version => 0,
21+ examples => 0,
2122);
2223
2324GetOptions(
24- ' count|c=i' => \$opts {count },
25- ' length|l=i' => \$opts {length },
26- ' smart|s' => \$opts {smart },
27- ' separator|S=s' => \$opts {separator },
28- ' help|h|?' => \$opts {help },
29- ' man|m' => \$opts {man },
30- ' version|v' => \$opts {version },
31- ' examples|e' => \$opts {examples },
25+ ' count|c=i' => \$opts {count },
26+ ' length|l=i' => \$opts {length },
27+ ' smart|s' => \$opts {smart },
28+ ' unique|u' => \$opts {unique },
29+ ' separator|S=s' => \$opts {separator },
30+ ' help|h|?' => \$opts {help },
31+ ' man|m' => \$opts {man },
32+ ' version|v' => \$opts {version },
33+ ' examples|e' => \$opts {examples },
3234) or pod2usage(2);
3335
3436# Handle special options
3537if ($opts {version }) {
36- print " random-string version $VERSION \n " ;
37- exit 0;
38+ print " random-string version $VERSION \n " ;
39+ exit 0;
3840}
3941
4042pod2usage(1) if $opts {help };
4143pod2usage(-exitval => 0, -verbose => 2) if $opts {man };
4244
4345if ($opts {examples }) {
44- show_examples();
45- exit 0;
46+ show_examples();
47+ exit 0;
4648}
4749
4850# Get the pattern from command line
4951my $pattern = shift @ARGV ;
5052
5153unless (defined $pattern ) {
52- print STDERR " Error: Pattern required\n\n " ;
53- pod2usage(1);
54+ print STDERR " Error: Pattern required\n\n " ;
55+ pod2usage(1);
5456}
5557
5658# Validate options
5759if ($opts {count } < 1) {
58- die ' Error: count must be at least 1' ;
60+ die " Error: count must be at least 1\n " ;
5961}
6062
6163# Decode escape sequences in separator
@@ -66,25 +68,25 @@ $opts{separator} =~ s/\\0/\0/g;
6668
6769# Create generator
6870my $gen = eval {
69- Data::Random::String::Matches-> new($pattern , $opts {length });
71+ Data::Random::String::Matches-> new($pattern , $opts {length });
7072};
7173
7274if ($@ ) {
73- die " Error creating generator: $@ " ;
75+ die " Error creating generator: $@ \n " ;
7476}
7577
7678# Generate strings
7779my @results ;
7880for (1 .. $opts {count }) {
79- my $str = eval {
80- $opts {smart } ? $gen -> generate_smart() : $gen -> generate();
81- };
82-
83- if ($@ ) {
84- die " Error generating string: $@ " ;
85- }
86-
87- push @results , $str ;
81+ my $str = eval {
82+ $opts {smart } ? $gen -> generate_smart() : $gen -> generate();
83+ };
84+
85+ if ($@ ) {
86+ die " Error generating string: $@ \n " ;
87+ }
88+
89+ push @results , $str ;
8890}
8991
9092# Output results
@@ -94,7 +96,7 @@ print "\n" unless $opts{separator} =~ /\n$/;
9496exit 0;
9597
9698sub show_examples {
97- print <<'EXAMPLES' ;
99+ print <<'EXAMPLES' ;
98100Examples:
99101
100102 # Generate a single 4-digit number
@@ -131,14 +133,14 @@ Examples:
131133 random-string '[A-Z]{3}\d{4}' -c 100 --smart
132134
133135Common patterns:
134- \d{4} - 4-digit PIN
135- [A-Z]{2}\d{3} - License plate style
136- \d{3}-\d{3}-\d{4} - Phone number
137- [a-z]+@[a-z]+\.com - Simple email
138- [A-Fa-f0-9]{32} - MD5 hash
139- [A-Za-z0-9]{20} - Random token
140- (foo|bar|baz) - One of three options
141- (\w{4})-\1 - Repeated pattern
136+ \d{4} - 4-digit PIN
137+ [A-Z]{2}\d{3} - License plate style
138+ \d{3}-\d{3}-\d{4} - Phone number
139+ [a-z]+@[a-z]+\.com - Simple email
140+ [A-Fa-f0-9]{32} - MD5 hash
141+ [A-Za-z0-9]{20} - Random token
142+ (foo|bar|baz) - One of three options
143+ (\w{4})-\1 - Repeated pattern
142144
143145EXAMPLES
144146}
@@ -154,14 +156,14 @@ random-string - Generate random strings matching a regular expression
154156random-string [options] PATTERN
155157
156158 Options:
157- -c, --count N Generate N strings (default: 1)
158- -l, --length N Set length for fallback generation (default: 10)
159- -s, --smart Use smart generation only (faster)
160- -S, --separator STR Separator between outputs (default: newline)
161- -e, --examples Show usage examples
162- -h, --help Show brief help
163- -m, --man Show full manual
164- -v, --version Show version
159+ -c, --count N Generate N strings (default: 1)
160+ -l, --length N Set length for fallback generation (default: 10)
161+ -s, --smart Use smart generation only (faster)
162+ -S, --separator STR Separator between outputs (default: newline)
163+ -e, --examples Show usage examples
164+ -h, --help Show brief help
165+ -m, --man Show full manual
166+ -v, --version Show version
165167
166168=head1 DESCRIPTION
167169
@@ -219,42 +221,42 @@ Print version information and exit.
219221
220222=head2 Character Classes
221223
222- [a-z] Lowercase letters
223- [A-Z] Uppercase letters
224- [0-9] Digits
225- [abc] Specific characters
226- [^a-z] Negated class
224+ [a-z] Lowercase letters
225+ [A-Z] Uppercase letters
226+ [0-9] Digits
227+ [abc] Specific characters
228+ [^a-z] Negated class
227229
228230=head2 Escape Sequences
229231
230- \d Digit [0-9]
231- \w Word character [a-zA-Z0-9_]
232- \s Whitespace
233- \D Non-digit
234- \W Non-word character
232+ \d Digit [0-9]
233+ \w Word character [a-zA-Z0-9_]
234+ \s Whitespace
235+ \D Non-digit
236+ \W Non-word character
235237 \t \n \r Tab, newline, carriage return
236238
237239=head2 Quantifiers
238240
239- {n} Exactly n times
240- {n,m} Between n and m times
241- {n,} At least n times
242- + One or more
243- * Zero or more
244- ? Zero or one
241+ {n} Exactly n times
242+ {n,m} Between n and m times
243+ {n,} At least n times
244+ + One or more
245+ * Zero or more
246+ ? Zero or one
245247
246248=head2 Groups and Alternation
247249
248- (...) Capturing group
249- (?:...) Non-capturing group
250- | Alternation (cat|dog)
251- \1 \2 Backreferences
250+ (...) Capturing group
251+ (?:...) Non-capturing group
252+ | Alternation (cat|dog)
253+ \1 \2 Backreferences
252254
253255=head2 Other
254256
255- . Any character
256- ^ Start anchor (stripped)
257- $ End anchor (stripped)
257+ . Any character
258+ ^ Start anchor (stripped)
259+ $ End anchor (stripped)
258260
259261=head1 EXAMPLES
260262
0 commit comments