Go Back   Persianhub > Information Center > General Help

Reply
 
LinkBack Thread Tools
Old 09-08-06, 14:51   #1 (permalink)
Forum Legend
 
Tayyare's Avatar
 
Join Date: Mar 2005
Posts: 1,983
Credits: 2,651
Thanks: 71
Thanked 111 Times in 89 Posts
Perl Script - Help -

Salam,

Man ye moshkeli paida kardam va har website ke miram bazam motevajeh nemisham chi kar bayad bekonam, man ye scrip mikham benevisam ke in karo bekone.

ye input file daram ke extension-e .txt dare, bad dar in file yek chizayi neveshte shode ke ba "," (comma/virgool) joda shodan. man mikham ye scrip ba perl benevisam ke in information ke beine virgool-ha hasto dar biaram va rooye output screen khat be khat print konam.

Age kesi ashnayi ba perl dare mamnoon misham komak bekone.

File: XXXXXXX, YYYYYY, ZZZZZZZ


output:
XXXXXXX
YYYYYY
ZZZZZZZ

__________________
Religion can never reform mankind because religion is slavery.

Tayyare is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 15:13   #2 (permalink)
Founder
 
darvish's Avatar
 
Join Date: Dec 2003
Location: United States of America
Posts: 3,801
Credits: 480,695
Thanks: 1,384
Thanked 1,294 Times in 516 Posts
Send a message via AIM to darvish Send a message via Yahoo to darvish
cheghadr perl kar kardi?

perldoc -f split

ye negah bendaz, tokenize kardan kaare asoonie too perl
__________________
I do love my Koala
darvish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 15:35   #3 (permalink)
Founder
 
darvish's Avatar
 
Join Date: Dec 2003
Location: United States of America
Posts: 3,801
Credits: 480,695
Thanks: 1,384
Thanked 1,294 Times in 516 Posts
Send a message via AIM to darvish Send a message via Yahoo to darvish
moshkelet hal shod ya na hanooz?
__________________
I do love my Koala
darvish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 15:39   #4 (permalink)
Forum Legend
 
Tayyare's Avatar
 
Join Date: Mar 2005
Posts: 1,983
Credits: 2,651
Thanks: 71
Thanked 111 Times in 89 Posts
ziad kar nakardam, vali kasi ke ghable man inja kar mikarde ye script neveshte bad comment nakarde manam moondam ke aslan in code chie, variabla kodooman, kholase gand zade be harchi programming.

hala mamnoon az lotfet, beram serach konam vase in bebinam chi paida mikonam.
__________________
Religion can never reform mankind because religion is slavery.

Tayyare is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 15:42   #5 (permalink)
Founder
 
darvish's Avatar
 
Join Date: Dec 2003
Location: United States of America
Posts: 3,801
Credits: 480,695
Thanks: 1,384
Thanked 1,294 Times in 516 Posts
Send a message via AIM to darvish Send a message via Yahoo to darvish
bebin ye raahe kheili asoon ke split koni hamin split e masalan:

print join('\n\n', split(/,/, 'Khomeini,Jallad,Khamenei,ValadeZena'));

output mishe:
Khomeini
Jallad
Khamenei
ValadeZena


vali age masalan dashte bashi blah,"blah, salam",hala

age bekhai beshe

blah
blah, salam
hala

bayad regular expression benevisi

vali age mese example e bala e ke dadam, oono bezan moshkelet halle.
__________________
I do love my Koala
darvish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 16:02   #6 (permalink)
Forum Legend
 
Tayyare's Avatar
 
Join Date: Mar 2005
Posts: 1,983
Credits: 2,651
Thanks: 71
Thanked 111 Times in 89 Posts
darvish jan dastet dard nakone, man in karo kardam but how can I use this command if I have an input file, for example I have this file File.txt and thats what my script reads and this is my script:

$basedir="/opt/redknee/home/rkadm/DataChargin";
$extension="txt";
$outdir="/opt/redknee/home/rkadm/DataChargin";
$ofile="results";
$ofileext="txt";

@files=`ls $basedir/*$extension`;

foreach $ifile (@files)
{
@list =();
chop ($ifile);
open (ifp,"$ifile");
print "+================================================ ==+\nchecking file $ifile...\n\n";

## places all records into an array @list
foreach $item (<ifp>)
{
if (!($item=~/^cdma/))
{
chop ($item);

************************************
push @list, $eachline;
}
}
print @list;
}

hala inja ke * gozashtam bayad in code shomaro benevisam, vali chetori mitoonam avazesh konam ke File.txt ro bekhoone??
__________________
Religion can never reform mankind because religion is slavery.

Tayyare is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 16:12   #7 (permalink)
Founder
 
darvish's Avatar
 
Join Date: Dec 2003
Location: United States of America
Posts: 3,801
Credits: 480,695
Thanks: 1,384
Thanked 1,294 Times in 516 Posts
Send a message via AIM to darvish Send a message via Yahoo to darvish
ok,
in script mireh too path e /opt/redknee/home/rkadm/DataChargin, harchi file hast ke extension e .txt dare ro open mikone, bad shoroo mikone khoondan (ifp file handle e, mese file handle too C). bad 'chop' mikone, yani akharin character e string ro mikkane (delete mikone).

hala oonja ke setareh hast, age mikhai hamechio tokenzie kone bar asase comma bezar:

@list = join('\n\n', split(/,/, $item));


monteha, nemidoonam to inkaro mikhai vase hameye text file haye oonto bokoni (above code) ya inke faghat mikhai fili be esme 'File.txt' o open kone va inkaro bokone?
__________________
I do love my Koala
darvish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 16:26   #8 (permalink)
Forum Legend
 
Tayyare's Avatar
 
Join Date: Mar 2005
Posts: 1,983
Credits: 2,651
Thanks: 71
Thanked 111 Times in 89 Posts
are darvish jan, in scripto hamin sobh ba yeki az bacheha neveshtim vali harkari kardam ke tokenize kone natoonestam, service shodam be molla. dar vaghe in script run mishe va too oon folder har fili ke .txt extension dashte basharo baz mikone bad bayad tokenize bekone, bad man 2-3 az in fieldaro mikham ke betoonam baham jam konam bill befrestam dame khooneye moshtari. albate alan testing hastesh va file asli .txt nist va .act hast

alan beram in karo bekonam bebinim chi mishe, damet khaily garm.
__________________
Religion can never reform mankind because religion is slavery.

Tayyare is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-08-06, 20:40   #9 (permalink)
Staff
 
Ehsan Z.'s Avatar
 
Join Date: Feb 2004
Location: Sydney, AU
Posts: 2,231
Credits: 512,340
Thanks: 147
Thanked 431 Times in 220 Posts
Quote:
Originally posted by Tayyare

@files=`ls $basedir/*$extension`;


hala inja ke * gozashtam bayad in code shomaro benevisam, vali chetori mitoonam avazesh konam ke File.txt ro bekhoone??
motmaen nistam vali bayad yechizi too in mayeha bashe

@files=`ls $basedir/File.$extension`;
or
@files=`ls $basedir/."File.".$extension`;
or
@files=`ls $basedir/.'File.'.$extension`;

ya mitooni oon bala ke extention ro define kardi "txt" ro ba "File.txt" replace koni
__________________
Ehsan Z. is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 16-08-06, 11:32   #10 (permalink)
Forum Legend
 
Tayyare's Avatar
 
Join Date: Mar 2005
Posts: 1,983
Credits: 2,651
Thanks: 71
Thanked 111 Times in 89 Posts
Agha dame hamatoon garm, in scripte ma kar kard... faghat alan ye bug dare oonam ine ke:

when it tokenizes the items between the commas, it removes the last element of the previous item, for example if I have this:

123456789,01010101,tayyare

when it tokenizes it, it give me this:
12345678,0101010,tayyar

hamintor ke mibinim shomareye 9 va 1 va e az itema oftade, nemidoonam cheshe.

mamnoon misham komak farmayid.
__________________
Religion can never reform mankind because religion is slavery.

Tayyare is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Persianhub > Information Center > General Help

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Orkut Script Amir General Help 11 16-10-04 04:12


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

RSS Feed w3-css w3-xhtml Join us in Facebook
Rules Terms of Services Policy Advertisement

Designed by LastBrush
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
2004 - 2009 © Persianhub Network