LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-25-2012, 04:42 AM   #1
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Rep: Reputation: Disabled
Perl scripting


Hi Everyone,

I new to linux,
And more over I started learning Perl scripting.
Initially I installed perl in my OS and in web I got some tutorials also.

I am not able to write a script for the following requirement " I am having excell file (.xlsx) ,and I want a script that read the excell file and prints same content in the excel sheet "
 
Old 07-25-2012, 04:44 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
http://www.ibm.com/developerworks/li...rary/l-pexcel/
 
Old 07-25-2012, 04:57 AM   #3
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Thanks for your immediate reply.
I saw the link and its good.....but the thing is I did not understand it ,I feel I need line to line explanation.( variables , etx ....).
 
Old 07-25-2012, 05:27 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
so ask, what is ok, what is unclear....
 
Old 07-25-2012, 05:31 AM   #5
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
so ask, what is ok, what is unclear....
use Spreadsheet::ParseExcel; ### why this is written

my $oExcel = new Spreadsheet::ParseExcel; ## what is $oExcel

die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV; ## this one also

my $oBook = $oExcel->Parse($ARGV[0]); ## did not understand
my($iR, $iC, $oWkS, $oWkC); ## did not understand
print "FILE :", $oBook->{File} , "\n"; ## did not understand
print "COUNT :", $oBook->{SheetCount} , "\n"; ## did not understand

print "AUTHOR:", $oBook->{Author} , "\n" ## did not understand
if defined $oBook->{Author};

for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) ## did not understand
{
$oWkS = $oBook->{Worksheet}[$iSheet]; ## did not understand
print "--------- SHEET:", $oWkS->{Name}, "\n";
for(my $iR = $oWkS->{MinRow} ;
defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; ## did not understand
$iR++) ## did not understand
{
for(my $iC = $oWkS->{MinCol} ; ## did not understand
defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; ## did not understand
$iC++) ## did not understand
{
$oWkC = $oWkS->{Cells}[$iR][$iC]; ## did not understand
print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC) ## did not understand
 
Old 07-25-2012, 05:35 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
here is the first one: the command use
 
Old 07-25-2012, 08:02 AM   #7
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
here is the first one: the command use
yah I understood about "USE"...Can u please explain about the rest of the program....
Is This the only way we write or any other way??....which will be bit easy than this .....
 
Old 07-25-2012, 09:02 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
the next one is to understand how the variables used in perl, what is my: http://perldoc.perl.org/functions/my.html, and here is a link about objects in perl: http://perldoc.perl.org/perlobj.html
If you want to use perl, this is the way.
 
Old 07-25-2012, 03:42 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-26-2012, 05:47 PM   #10
MarxBro
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
Cool Let's see...

Quote:
Originally Posted by ravi_nandula View Post
yah I understood about "USE"...Can u please explain about the rest of the program....
Is This the only way we write or any other way??....which will be bit easy than this .....
Perl is full of 'dialects' (those are just ways of do things), but this is not the case as is quite standart. The script you bring on topic before, "uses" a library which is on itself an object, thats why we find something like:
Code:
my $oBook = $oExcel->Parse($ARGV[0]);
The '->' calls a method from an object. The '$ARGV[0]' is a Perl default array that stores the arguments passed to the script file on run time, in this case is a filename as the script is written to be used like this way:
Code:
scriptName.pl somefile.xlsx
.
The 'perlvar' man page will give you a better panorama of that part. Also check 'perlobj' for object programming on Perl.
To any doubt about built-in functions, you can use:
Code:
perldoc -f functionName
perldoc -f defined # for example
I assume you missed 3 final closing brackets '}' (maybe a header with the hashbang for perl and a 'use strict' perhaps?), if so, the script is quite simple: it iterates over all columns and rows of all sheets on the file, print the coordenate of location and the value of it on the line:
Code:
print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC)
which is the same of ask 'if this cell has something, print it'.

So, a lot to said on your previous question as is very vague, btw, but will be brief:
-If you have an error on this code, and assuming is well written, check if you do have that library you're calling, first line you quoted 'use Spreadsheet::ParseExcel;'. Check if is on your system, there are lots of ways of do it, my way is just by calling the doc of it:
Code:
perldoc Spreadsheet::ParseExcel
If you see something that looks like a man page, you have it there, if an error you don't, go install it.
-The only trick to learn from the code you bring on topic is recursion, "for each sheet, walk by each column, for each column, walk by each row and print the content". The rest of it, is just a definition of where it will happen, what we will need... no mistery, just a workaround to get an excel file opened.
Perl has plenty ways of do recusion and those are very flexible, check on perldoc for for, foreach, do, while, until...
-You want to write something like that? Ok, install the library if not there, make some coffee and read the docs of the library; ther is not much way around it so far, just study... and cheat this way:
Code:
man perlcheat
Hope this helps you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl scripting question Quest ion Programming 10 11-13-2013 09:56 AM
perl scripting question Quest ion Programming 4 12-02-2011 03:39 AM
Perl Scripting magin Programming 9 04-24-2007 08:40 AM
question about perl scripting feetyouwell Linux - Software 2 02-13-2004 03:11 PM
Perl scripting Rameriez Programming 4 02-03-2003 01:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration