Linear Search in Perl (original) (raw)
Published on 13 February 2025 (Updated: 13 February 2025)
Welcome to the Linear Search in Perl page! Here, you'll find the source code for this program as well as a description of how the program works.
Current Solution
#!/usr/bin/perl
my $arguments_used = scalar @ARGV;
if($arguments_used < 2)
{
die "Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")\n";
}
my @input_array = @ARGV;
my $input_string = pop @ARGV;
my @trimmed_string = split(',', @input_array[0]);
my $found_it = 0;
if(scalar@trimmed_string < 1)
{
die "Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")\n";
}
for(my <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>=</mo><mn>0</mn><mo separator="true">;</mo></mrow><annotation encoding="application/x-tex">i = 0; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8389em;vertical-align:-0.1944em;"></span><span class="mord">0</span><span class="mpunct">;</span></span></span></span>i < scalar(@trimmed_string); $i++)
{
if($trimmed_string[$i] == $input_string)
{
$found_it = 1;
}
}
print $found_it ? "true" : "false";
Linear Search in Perl was written by:
- Tim W
If you see anything you'd like to change or update, please consider contributing.
How to Implement the Solution
No 'How to Implement the Solution' section available. Please consider contributing.
How to Run the Solution
No 'How to Run the Solution' section available. Please consider contributing.