Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why use perl?

Status
Not open for further replies.

jcisco

Programmer
Sep 17, 2002
125
US
i'm searched through some threads and read the one dated on 06/23/01 (posted 05/28/00). But really i'm not understanding really why use perl. You have JSP, PHP (although really a web page thing more than anything), and the new kid on the block ASP.NET (which i like). either way i have to learn perl but i'm wondering why are people using it? is it better than say ASP.NET, or JSP? and if so why did they make it compatable for .NET? Now i know .NET is (for the moment just ran on windows machines) but the mono project and a few other's are fixing that problem.
And another thing can perl use soap? I'm creating all my web services (for ease of use more than anything) with VS.NET, but i'm thinking that i will have to call via perl. --------------
:)
 
Holy crap! Are you kidding me? Perl is the best! Nothing else even compares. Yes, you can do soap or anything else which is possible with any other language, plus things that aren't. And you'll use 10 times less code to do it.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
tom: perl is the best...
for people, they are satisfied if "it works"
without knowining why && how.
it's important how many lines a good code contains ?
say please what's not possible in 'c', remember
perl is 'c'. -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Generally, Perl is designed to accomplish easy tasks in very few lines of code. For example, in a UNIX-ey type of environment, this code emulates the cat utility, assuming you redirect the input.

====
#! /usr/local/bin/perl
while(<>) {
print;
}
====

For active web content, there are reasons to use each of the technologies you mentioned. I use Perl at work, because it's very flexible, free, and seems to have a shorter development cycle in my shop than some alternatives we've tried. However, in situations where you may not have much control over the server, you may want to consider alternative solutions. In a UNIX-ey enviornment, CGI scripts have to be marked executable, whereas technologies like PHP include function in the content, so those files can just be readable.

I like Perl, and I know a lot of other people do, too. I use it for more than just web content, so that may contribute to its usefulness. It is hard to use Active Server Pages to do something unrelated to delivering web content. Perl can happily do things like that, too. It's kind of like having a tool that configures itself to be able to help address any problem.

Your mileage may vary.

vrj
 
Perl does web stuff.
Perl does databases stuff.
Perl does strong regex stuff.
Perl does GUI (contrary to popular belief)
Perl does Object Oriented stuff.
Perl does nearly anything you want to try to do.
(Yes it is 'C', but C lacks Perl's rich syntax.)
Perl does XML.
Perl does SOAP.
Perl does OLE
(a little dated - read/write Excel or Word files).
Perl does .NET.
I could go on...

Perl has enough structure to make things work with out having so much structure that it slows development down. Enough structure to facilitate multideminsional memory structures and at the same time there are no variable types(int, decimal, string, etc). You don't have to worry about casting a variable from one type to another so you can do some work on it. You just go ahead and do the work.

Perl can be Object-Oriented or procedural. Or,(the part I like best) a single piece of Perl can use OO tactics and procedural tactics where each works best.

Perl has a very active user base with lots of sites and groups like TTs available to deliver support.

For a modest price, you can buy tools to turn Perl apps into Windows executables.

You can buy proffessional support from companies like active state, if you need and want.

I sat down last night (just got a new digital camera) and wrote a simple little Perl/Tk GUI on my linux box to connect to (mount) the USB camera (if it is not already mounted), create a new date-named directory(if it is not already there), copy the the contents of the camera to the dir, and finally unmount the USB device. It took about an hour to get it working and tweak the color scheme for the GUI. It gives the user appropriate error messages if it can't find the camera or can't create the new dir. The entire piece of code is a whopping 83 lines long including comments in the top flower-box. Now, my wife and kids can sit down, plug the camera in, double-click a desktop icon of a camera, and use a convinient little tool to download the camera to disk.

Perl does that, that quickly and easily.
I write very little C, but enough to know that even if I were a lot better with C, that application (trivial as it is) would take longer than an hour and more than 83 lines to write.

In case you can't tell, I like Perl. ;-) 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I think the point has been made but I would like to go a little farther. The PERL interpreter can be embedded in to C++ and C#. This advantage gives PERL the ability to expand itself beyond its orginal conception. You can use PERL to accomplish simple tasks that it is good at within a C++ application.

Another Point, every language that has been developed for web application has emulated what PERL already had the capability to do. Simply, PERL has been copied but not duplicated! Learning PERL as a base language gives the programer a set of tools that make seemingly complex programming a snap.

Finally, ActiveState 5.6.1 allows perlscript to be used in ASP and ASP.NET application. Its power continues to grow
 
Hi jcisco,

I'm, glad you asked that question, because I just recently began using Perl, and I've been so impressed that I've been asking just the opposite question: &quot;Why not use Perl?&quot; or putting it another way, &quot;Why aren't more people using Perl?&quot;

I'm developing an online forum, sort of like this one. I've used ASP in the past, and never really liked it. I decided to give Perl a try, and I'm so glad I did. So far it has been my experience that Perl is easier to use, easier to debug, and a lot more fun to work with. My scripts seem to run just as fast as ASP scripts, if not faster. And so far, I haven't found anything I can't do with it.

I used to hear complaints that Perl/CGI wasn't fast enough, but some of the newer modules have apparently solved that problem.

Even though VBScript has an easy to learn syntax, I'm actually finding Perl easier to use, and definitely easier to debug. However, I haven't worked with .Net yet.

Until now most of my programming experience has been with Java. Perl has a lot of built in functions that enable me to accomplish with just one word, a task that I'm accustomed to having to write my own function for in Java. And why should I use both Servlets and JSPs to accomplish what Perl can do alone? Why make it so complicated if I don't have to? Plus, if I did use Java for this project, it would take forever. I like Java, and I'm better at Java than Perl, I have more experience with Java, but it would still take me a lot longer to build this App in Java.

One of the coolest things about Perl is that variable names can be included right in Strings, without worrying about the quotes. One thing I hate about ASP is the millions of double & single quotes that make the code into a spaghetti of quotes. I mean stuff like the following:

&quot;'&quot;blah blah&quot;'&quot;

I hate that, but I didn't know there was an alternative until I used Perl. That kind of nonsense just isn't necessary in Perl. With Perl I just put a quote aroung the whole thing and forget about it.

It's stuff like this that makes Perl so easy and fast to work with. Perl is quickly becoming my favorite language. I hope I can continue to work with it.

So what is the answer to my question above? I can only speculate that languages like Java and VB have become so popular in part because they have powerful marketing forces behind them. Perl is totally independent. No one is spending big bucks to promote Perl the way that Sun and MS promote their technologies. But so far I see no evidence that Perl is anything less than great! I'm not saying that Perl is better. They are all good.

Good luck,

Greg _______________________________________
constructed from 100% recycled electrons
 
One other thing that everyone else left out... it is much more difficult to have buffer overruns in Perl because it dynamically allocates memory for strings and arrays. Thus, all applications -- and especially web apps, which are more vulnerable -- which are written in Perl will tend to be more secure.

Jamisar, it certainly does matter how many lines of code a program requires. It directly relates to how long it takes to write it, how readable it is, and how many hiding places the bugs have! Moreover, the things which are simplified in Perl have C equivalents (albeit much more complex), but all of the optimization has already been done for you, so the Perl version will tend to run faster.

Hey goBoating, would you mind sharing the code you wrote for your digital camera? I got a Kodak Easyshare and I tried someone else's linux interface, but it didn't work right... it would read the camera's directory structure, but not the images themselves. I don't have much experience with reading from USB devices (in fact, none at all), so I'd love to take a look at your code, if you don't mind.

Thanks!
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
thanks everyone for replying. I was just wondering and you all have been a great help.

cheers
john --------------
:)
 
Hey Tom,
In order to get my machine to see my camera I had to add this to my /etc/fstab file.
Code:
/dev/sda1    /mnt/camera    vfat	noauto,sync,nosuid,user,unhide    0    0
That should be just one line.

I made a directory /mnt/camera/ for that mount to work on.

Then here's the code to the Tk critter. It is not the most sophisticated thing I've ever written but, it's functional. There are a few paths that will likely need to be tweaked. My Fujifilm camera shows up as just another file system. If yours does the same, the path inside the camera will likely be different. And there is an explicit path to my home dir on my machine that probably won't match your machine. Otherwise, it should work.

Code:
#!/usr/bin/perl
# nearly trivial script to mount /mnt/camera on
# /dev/ttyUSB1,
# create a new directory named with the current date/time,
# copy images from the camera to disk, and umount the 
# camera.
#-------------------------------------------------------------------`--
use strict;
use Tk;
use Tk::Pane;

my $message = 'Ready';
my $main = MainWindow->new();
$main->configure(-title=>'Camera 2 Disk', -background =>'blue');
$main->geometry('370x140+100+00');
my $label = $main->Label(-text =>'Digital Camera Tool',
            -relief => 'raised',
            -background =>'#42b4b4')
    ->pack(-side=>'top', -fill =>'both');

my $button_frame = $main->Frame(-relief=>'raised')
    ->pack(-side => 'top', -fill => 'x');
my $dump = $button_frame->Button(-text => 'Dump',
             -command => \&get_files)
    ->pack(-side =>'left', -anchor => 'w');
$button_frame->Button(-text => 'Exit', -command => 'exit')
    ->pack(-side =>'right');
my $status = $main->Scrolled('Pane', -scrollbars => 'se', -relief => 'raised')
    ->pack(-side=>'bottom', -fill=>'both', -expand=>'y');
$status->Label(textvariable =>\$message,
            -relief => 'raised')
    ->pack(-side=>'top', -fill =>'both');
MainLoop();
#---------------------------------------------------------------------
sub get_files {
my $date = localtime;
my @time = split /\s|:/, $date;

my $new_dir = '/home/julmer/images/'.$time[1].'_'.$time[2].'_'.$time[6].'_'.$time[3].$time[4].$time[5];

my $mount = '';
my $cmd = &quot;mount /mnt/camera&quot;;
open(CAM,&quot; $cmd 2>&1 |&quot;) || die &quot;Failed open: $!\n&quot;;
while (<CAM>) { $mount .= $_ ; }
close CAM;

if ($mount =~ /already mounted/i)
    {
    $message = '/mnt/camera is already mounted';
    }
elsif ($mount =~ /no medium found|not a valid/i)
    {
    $message = &quot;Mount Failed: $mount Be sure the camera is connected&quot;;
    $message .= &quot;\nand turned on in USB DSC mode.\n&quot;;
    return;
    }

$message = '';
my @files = `ls /mnt/camera/dcim/100_fuji/`;
chomp (@files);
if ($#files > 0 )
    {
    mkdir($new_dir);
    foreach (@files)
        {
        my $from = '/mnt/camera/dcim/100_fuji/'.$_;
        my $to = $new_dir.&quot;/$_&quot;;
        my $cmd = qq(cp $from $to);
        $message .= &quot;Copying $_ to disk.\n&quot;;
        `$cmd`;
        }
    }

$cmd = &quot;umount /mnt/camera&quot;;
open(CAM,&quot; $cmd 2>&1 |&quot;) || die &quot;Failed open: $!\n&quot;;
while (<CAM>) { $mount .= $_ ; }
close CAM;
$message .= &quot;\nDone!\n&quot;;
}

'just scream (type) if you have any questions. I'll probably continue to play with this a little.... add a progress bar.... tweak the aesthetics a little.... that kind of thing. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
goBoating,

Thanks, that's awesome. I'll try to get it to work on my system after the holiday and let you know how it goes. Have you thought about putting this on sourceforge?
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Sorry to continue the off-topic thread, but, I am embarrassed to have to correct a rookie mistake in the Tk application I posted above.
I used &quot;if ($#files > 0)&quot; to check if the camera had any images to download. If the camera had one and only one image, the application would fail to copy it to disk. I'm posting this updated code in case anyone might use the previous code. I don't want anyone to think they copied an image to disk, then delete it from their camera and then not have it at all.

Also, this version of the code includes a progress bar.

Code:
#!/usr/bin/perl
# nearly trivial script to mount /mnt/camera on /dev/ttyUSB1,
# create a new directory named with the current date/time,
# copy images from the camera to disk, and umount the camera.
#---------------------------------------------------------------------
$| = 1;
use strict;
use Tk;
use Tk::Pane;
use Tk::ProgressBar;

my $message = 'Ready';
my $main = MainWindow->new();
$main->configure(-title=>'Camera 2 Disk', -background =>'blue');
$main->geometry('370x200+100+00');
my $label = $main->Label(-text =>&quot;Digital Camera Tool\nCopy Images from Fuji FinePix to Disk&quot;,
            -relief => 'raised',
            -background =>'#42b4b4')
    ->pack(-side=>'top', -fill =>'both');

my $button_frame = $main->Frame(-relief=>'raised')
    ->pack(-side => 'top', -fill => 'x');
my $dump = $button_frame->Button(-text => 'Dump',
             -command => \&get_files)
    ->pack(-side =>'left', -anchor => 'w');

my $status_text = 'Ready';
my $status_label = $button_frame->Label(-textvariable =>\$status_text,
            -relief => 'raised',
            -background =>'grey77')
    ->pack(-side=>'left',-fill=>'both', -expand=>'1');

my $exit = $button_frame->Button(-text => 'Exit', -command => 'exit')
    ->pack(-side =>'right');

my $status = $main->Scrolled('Pane', -scrollbars => 'se', -relief => 'flat')
    ->pack(-side=>'top', -fill=>'both', -expand=>'y');
$status->Label(textvariable =>\$message,
            -relief => 'flat')
    ->pack(-side=>'top', -fill =>'both');

my $percent_done;
my $position = '0';
my $progress = $main->ProgressBar(-troughcolor => 'grey70',
        -width => 20,
        -length => 370,
        -anchor => 'w',
        -from => 0,
        -to => 100,
        -blocks => 0.1,
        -colors => [0, 'blue', 100],
    )->pack(-side=>'left', -fill=>'both');

$progress->value($position);

MainLoop();
#---------------------------------------------------------------------
sub get_files {
my $date = localtime;
my @time = split /\s|:/, $date;

my $new_dir = '/home/julmer/images/'.$time[1].'_'.$time[2].'_'.$time[6].'_'.$time[3].$time[4].$time[5];

my $mount = '';
my $cmd = &quot;mount /mnt/camera&quot;;
open(CAM,&quot; $cmd 2>&1 |&quot;) || die &quot;Failed open: $!\n&quot;;
while (<CAM>) { $mount .= $_ ; }
close CAM;

if ($mount =~ /already mounted/i)
    {
    $message = '/mnt/camera is already mounted';
    }
elsif ($mount =~ /no medium found|not a valid/i)
    {
    $message = &quot;Mount Failed: $mount Be sure the camera is connected&quot;;
    $message .= &quot;\nand turned on in USB DSC mode.\n&quot;;
    return;
    }

$message = '';
my @files = `ls /mnt/camera/dcim/100_fuji/`;
chomp (@files);
my $num_files = $#files + 1;
$message = $num_files.&quot;$files[0]&quot;;
my $file_count = '1';
# if ($#files > 0 ) # stupid!!
if ($files[0] =~ /\w/ )
    {
    $dump->configure(-state=>'disable');
    $exit->configure(-state=>'disable');
    mkdir($new_dir);
    foreach (@files)
        {
        my $from = '/mnt/camera/dcim/100_fuji/'.$_;
        my $to = $new_dir.&quot;/$_&quot;;
        my $cmd = qq(cp $from $to);
        $message = &quot;Copying $_ to disk.\n&quot;;
        `$cmd`;
	$percent_done = int(($file_count/$num_files) * 100);
	$progress->value($percent_done);
	$progress->update;
	$file_count++;
	$status_text = qq(Progress: $percent_done %);
        }
    $dump->configure(-state=>'normal');
    $exit->configure(-state=>'normal');
    }
$cmd = &quot;umount /mnt/camera&quot;;
open(CAM,&quot; $cmd 2>&1 |&quot;) || die &quot;Failed open: $!\n&quot;;
while (<CAM>) { $mount .= $_ ; }
close CAM;
$status_text = 'Done';
$message .= &quot;\nDone!\n&quot;;
}
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top