CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [BoJo] How to extract sub strings?: Edit Log


Aug 9, 2017, 2:01 PM

Views: 2542
Re: [BoJo] How to extract sub strings?

Hello BoJo:

ALWAYS use strict. In this case, it would have found one of your errors.

Every statement must end in a semicolon. This is not exactly true, but its not worth worrying about the exceptions because it never hurts.

The function 'system' is not the same as backticks. You need the backticks in both places.

The first argument of split is a regex, not a string.

The variable that you call $dtg is an array, not a scalar. It must be declared @dtg.

I expect that your script will work with these changes.

Although it 'works', it is a poor practice to declare all your variables at the start of the script.

It is very bad practice to use system or backticks when a perl solution is available. In your case, you should use the perl module Image::ExifTool rather than the shell utility.

Update: Added corrected code (untested).

use strict;
use warnings;
my $picnames= `exiftool pic-0.jpg |grep 'Region Name'`;
print $picnames;
my $createdtg=`exiftool pic-0.jpg | grep 'Create Date'`;
print $createdtg;
my @dtg=split(/ /, $createdtg);
print $dtg[4] ;

Good Luck,

(This post was edited by BillKSmith on Aug 9, 2017, 2:32 PM)

Edit Log:
Post edited by BillKSmith (Veteran) on Aug 9, 2017, 2:32 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives