Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
143 user(s) are online (137 user(s) are browsing Forums)

Members: 0
Guests: 143

more...

Support us!

Headlines

 
  Register To Post  

AREXX --> Perl or Python
Home away from home
Home away from home


See User information
Hi guys,

I've done some "simple" scripting in AREXX for a while now.

I've hit the borders of what's possible in AREXX when it comes to processing *large* files and changing them (strip, substr etc.) and writing them back to another file.

I get the dreaded "ram usage goes beyond ~70% silent system freeze" every time i want to process a 1MB+ sized text file.

I'm doing a simple task like opening the file, reading in line for line and writing it back into another file ... not possible with AREXX as it will eat away my 2 GB of RAM and freeze solid

Now, i'd like to switch to one of the other supported scripting languages.

Can anyone point me to a good online tutorial (a printed manual would be even better) or at least tell me which of the two languages would be easier to switch to coming from AREXX?

I tried both already with copy and paste and opening and reading the same file and at least both doesn't eat up all my ram (albeit it seems Perl - or was it python? - doesn't free all of it after the script finished)

Just for the sake of completeness, here's what i want to do (and no, i don't want anyone to write it for me)

1) Open a file
2) read the file line by line
3) check if a special condition is met
4) if so, change the line accordingly (AREXX SUBSTR)
5) write it back to another file
6) exit

The goal is to fetch a file from the net, change it accordingly to that it can be used in AmigaOS

Thanks a lot in advance

Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@Raziel

Sorry you originally asked about this in PM and I sent you and extansive reply, which somehow disppeared and I didn;t get round to re replying....

Quote:

I've done some "simple" scripting in AREXX for a while now.

I've hit the borders of what's possible in AREXX when it comes to processing *large* files and changing them (strip, substr etc.) and writing them back to another file.

I get the dreaded "ram usage goes beyond ~70% silent system freeze" every time i want to process a 1MB+ sized text file.



Really with 1Mb files? I was imagining that you were processing simething much larger when you PMed me.

/* slurp file */


options results


if open("FH","SAM_Ram Disk:webhitdata.csv","r"then do
    if 
open("OUT","ram:processed","W"then do
        do while ~
eof("FH")
            
line readln("FH")
            
call writeln("OUT",line)
        
end
    end
end


Loads and writes out a 1.5 Mb CSV file, with about 11000 lines, with barely a ripple in memory usage.


Quote:

I'm doing a simple task like opening the file, reading in line for line and writing it back into another file ... not possible with AREXX as it will eat away my 2 GB of RAM and freeze solid


Okay see above, what else are you doing that uses up the memory? Are you trying to hold all the data in memory before writing it out?

Quote:

Now, i'd like to switch to one of the other supported scripting languages.

Can anyone point me to a good online tutorial (a printed manual would be even better) or at least tell me which of the two languages would be easier to switch to coming from AREXX?


python is easier than perl but perl may be nore suited to what you are doing, though without fine detail it hard to say exdactly.

Quote:

I tried both already with copy and paste and opening and reading the same file and at least both doesn't eat up all my ram (albeit it seems Perl - or was it python? - doesn't free all of it after the script finished)

Just for the sake of completeness, here's what i want to do (and no, i don't want anyone to write it for me)

1) Open a file
2) read the file line by line
3) check if a special condition is met
4) if so, change the line accordingly (AREXX SUBSTR)
5) write it back to another file
6) exit

The goal is to fetch a file from the net, change it accordingly to that it can be used in AmigaOS

Thanks a lot in advance


Perl frame work is as follows.

#!perl

open IN,  "<""SAM_Ram Disk:webhitdata.csv" or die "Couldn't open input file";
open OUT">""ram:processed" or die "Couldn't open outputfile";

while (<
IN>) {

    print 
OUT $_
};


or

#!perl

open IN,  "<""SAM_Ram Disk:webhitdata.csv" or die "Couldn't open input file";
open OUT">""ram:processed" or die "Couldn't open outputfile";

foreach 
$line (<IN>)  {
    
$line =~ s/Mozilla/Aweb/;
    print 
OUT $line
};


The above uses a regular expression to substitute AWeb for Mozilla for each line where it appears.

For perl documentation simply do

perldoc <filename>

eg

perldoc perlsyn (general syntax)
perldoc perlfunc (all the functions)

perldoc perlre (reguar expressions)

or perldoc -f <somefunctionname>


Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@Raziel

[quote]Just for the sake of completeness, here's what i want to do (and no, i don't want anyone to write it for me)

1) Open a file
2) read the file line by line
3) check if a special condition is met
4) if so, change the line accordingly (AREXX SUBSTR)
5) write it back to another file
6) exit
[quote]

Here's the same thing in python:

#!C:Python
f1=open('load.txt''r')
f2=open('save.txt''wb')
for 
line in f1:
  
line line.strip()
  
line line.replace('original text''amiga text')
  
f2.write(line '\\n')
f1.close()
f2.close()

You can add as many replace lines as you need.

Edit: Tutorial here: http://www.tutorialspoint.com/python/

Edit2: Slightly more complicated version that excepts command line load and save parameters.

#!C:Python

import sysos.path

numargs 
len(sys.argv)
if 
numargs == : exit()
if 
numargs : exit()

loadfile sys.argv[1]
savefile sys.argv[2]

print 
'Reading: ' loadfile
print 'Saving as: ' savefile

if os.path.exists(loadfile):
 
f1=open('loadfile''r')
 
f2=open('savefile''wb')
 for 
line in f1:
  
line line.strip()
  
line line.replace('original text''amiga text')
  
f2.write(line '\n')
 
f1.close()
 
f2.close()


Edited by Severin on 2016/11/28 17:58:37
Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: AREXX --> Perl or Python
Amigans Defender
Amigans Defender


See User information
Why don't you modify your ARexx script so it reads and processes and writes line by line, instead of loading everything into memory at the start?

Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@all

Thanks for the hints, i'll check them out asap

@Chris

Thats what i think i already do.

open a file
read a line
process the line
write it back to another file
rinse repeat

doing it like above though, it will fill up my ram constantly until it freezes the system

here is the (broken and very rudimentary) script and the link to the file i let it run on.
Download the file and use it as argument

/*
Blacklist Creator
*/

PARSE ARG hosts_txt

x
=0
y
=0

OPEN
(hosts_read,hosts_txt,'R')
/* LASTPOS('.',working_line)-POS('.',working_line)+5 */
DO WHILE EOF(hosts_read)=0
    working_line
=READLN(hosts_read)
    IF 
SUBSTR(working_line,1,7)='0.0.0.0' THEN DO
        
working_line=SUBSTR(working_line,9)
        
x=x+1
        
IF POS('.'working_line)~=LASTPOS('.',working_lineTHEN
            probable_individual_link
=SUBSTR(working_line,POS('.',working_line)+1)
        ELSE
            
probable_individual_link=working_line
        
ENDIF
        IF 
probable_individual_link~=individual_link THEN DO
            
individual_link=probable_individual_link
            SAY individual_link
            y
=y+1
        END
    END
    
IF y=2000 THEN
        LEAVE
    
ENDIF
END

SAY 
"Links checked:" x
SAY 
"Individual links found:" y

EXIT 0


For now the script is supposed to only count individual links (speaking of the main sites, like google.com where the probable links can alter from ads1.google.com to ads99.google.com or whatever, it should just pick google.com and discard the rest etc.)

As i said, the script doesn't work like i want it to right now and i don't want a ready script written from any of you, i want to script it myself

But if you know how i can manage AREXX to not fill up the ram i'd be grateful

But just for the fun of it, try it and see how it eats away your ram.

I added a safe case where it stops after finding 2000 links, remove that and it will goe beyond the ram barrier that freezes the system


...

and no comments on my scripting, please

Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@Raziel

I removed the 200 line limit and ran your script on that data on my SAM, did not run out of memory, in fact didn't ever use much memory.

Is that the exact script you have been having issues with?

Quote:

and no comments on my scripting, please


Okay I won't mention that there is no such keyword as ENDIF in ARexx

the syntax is simply

if <condition> then <expression> else <other expression>

is all you need expression may be a do block if you need more than one statement

ie

if FOO = BAR THEN DO
/* lots of stuff */
END
ELSE DO
/* different stuff */
END

your not seeing an error as when ENDIF is uset it simply evaluates to 'ENDIF' (the string) rexx searches for a function in all the available hosts and does nothing if not found, since you don't have a function host added (ie address is REXX) it simply ignores it, if you had a host address set you would likely see an error

BTW Exit returns a string not a number. EXIT 0 is not meaningful in this context.

Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@broadblues

I tested it on my X1000.

On my public FE installation, I could reproduce the memory leakage, but on the beta, it worked fine. Running in and reading from RAM: in both cases.

Broadblues, did you test on the beta?

Best regards,

Niels

Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@nbache

I tested on my beta on the SAM, this is curious as there has been no change in rexxsyslib since Final Edition that I can see. ie libs at same version.

I will retry on FE in a bit.


Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
It does seem to leak in FE: But in an odd way, memeory usage as displayed by the WB header goes right down to 480Mb free then bounces back to 1400 Mb free and the machine remains usable except that all rexx related stuff then hangs.

Unsure what the chnage from FE: to beta is as all the obvious rexx related components appear the same RX Rexxmast and rexxsyslib being the most obvious.

Edit I removed the say statements to eliminate the console from enquiries..




Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@broadblues

Also leaks in 4.1 Update 6


Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@broadblues



Thanks for pointing out the mistakes i made in the script (that is very welcome'd, of course)

@nbache&broadblues

Thanks to you both for confirming the leakage and confirming that i'm not fantasizing things again

Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@Raziel

I converted your arexx script to python, it 369 bytes:

> blacklist_creator1.py
Lines checked: 40520
Individual links found: 38161
> get _runtime
0.868863

I also did a more complicated version that downloads the hosts file itself.

Catch me on IRC if you get stuck.

Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@Severin

I hate you





Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@broadblues

Quote:
Unsure what the chnage from FE: to beta is as all the obvious rexx related components appear the same RX Rexxmast and rexxsyslib being the most obvious.
Ram-handler? Elf.library? DOS?

Anyway, the good news is that the problem is (for us)/will be (for everybody) solved.

Best regards,

Niels

Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@Raziel

Just so you can hate me more:
> list blacklist_creator0.py 
blacklist_creator0
.py           268 -s--rw-d Today     01:43:42
1 file 
268 bytes 2 blocks used
blacklist_creator0.py 
Lines checked
:40520
Individual links found
:38161
get _runtime
0.669206
>


Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: AREXX --> Perl or Python
Just can't stay away
Just can't stay away


See User information
@Raziel

A little christmas present:

#!C:Python
X=Y=0
I
=open('hosts','r')
O=open('blacklist','wb')
for 
L in I:
    
X+=1
    
if L.startswith('0.0.0.0'):
        
L=L[9:]
        if 
L.count('.')>1:
            
L=L[L.find('.')+1:]
        
O.write(L)
        
Y+=1
I
.close()
O.close()
print 
"Lines checked:"+str(X)+"\\nIndividual links found:"+str(Y)


edit: changed indenting from tabs to spaces to make it more readable,


Edited by Severin on 2016/12/25 21:48:03
Edited by Severin on 2017/1/1 16:26:22
Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: AREXX --> Perl or Python
Home away from home
Home away from home


See User information
@Severin

/me smooches severin with a big, wet one...on the cheek, of course





...now, if i only had the time to do some sripting myself again :-/

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 2 ( 0 members and 2 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project